Ejemplo n.º 1
0
/*
 * call-seq:
 *    attr.prev -> node
 *
 * Obtain the previous attribute.
 */
static VALUE rxml_attr_prev_get(VALUE self)
{
  xmlAttrPtr xattr;
  Data_Get_Struct(self, xmlAttr, xattr);
  if (xattr->prev == NULL)
    return Qnil;
  else
    return rxml_attr_wrap(xattr->prev);
}
Ejemplo n.º 2
0
/*
 * call-seq:
 *    attributes.get_attribute("name") -> XML::Attr
 * 
 * Returns the specified attribute.
 * 
 * name: The name of the attribute, not including a namespace.
 *
 *  doc.root.attributes.get_attribute("foo")
 */
static VALUE
rxml_attributes_get_attribute(VALUE self, VALUE name) {
  xmlNodePtr xnode;
  xmlAttrPtr xattr;

  name = check_string_or_symbol(name);
  
  Data_Get_Struct(self, xmlNode, xnode);
  
  xattr = xmlHasProp(xnode, (xmlChar*)StringValuePtr(name));
  
  if (xattr)
    return(rxml_attr_wrap(xattr));
  else
    return(Qnil);
}
Ejemplo n.º 3
0
/*
 * call-seq:
 *    attributes.get_attribute("name") -> (XML::Attr | XML::AtrrDecl)
 *
 * Returns the specified attribute.  If the attribute does not 
 * exist but the document has an associated DTD that defines
 * a default value for the attribute, then a XML::AttrDecl is
 * returned.
 *
 * name: The name of the attribute, not including a namespace.
 *
 *  doc.root.attributes.get_attribute("foo")
 */
static VALUE rxml_attributes_get_attribute(VALUE self, VALUE name)
{
  xmlNodePtr xnode;
  xmlAttrPtr xattr;

  name = rb_obj_as_string(name);

  Data_Get_Struct(self, xmlNode, xnode);

  xattr = xmlHasProp(xnode, (xmlChar*) StringValuePtr(name));

  if (!xattr)
    return Qnil;
  else if (xattr->type == XML_ATTRIBUTE_DECL)
    return rxml_attr_decl_wrap((xmlAttributePtr)xattr);
  else
    return rxml_attr_wrap(xattr);
}
Ejemplo n.º 4
0
static VALUE rxml_xpath_object_tabref(xmlXPathObjectPtr xpop, int index)
{
  if (index < 0)
    index = xpop->nodesetval->nodeNr + index;

  if (index < 0 || index + 1 > xpop->nodesetval->nodeNr)
    return Qnil;

  switch (xpop->nodesetval->nodeTab[index]->type)
  {
  case XML_ATTRIBUTE_NODE:
    return rxml_attr_wrap((xmlAttrPtr) xpop->nodesetval->nodeTab[index]);
    break;
  case XML_NAMESPACE_DECL:
    return rxml_namespace_wrap((xmlNsPtr)xpop->nodesetval->nodeTab[index]);
    break;
  default:
    return rxml_node_wrap(xpop->nodesetval->nodeTab[index]);
  }
}