Esempio n. 1
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);
}
Esempio n. 2
0
/*
 * call-seq:
 *    XML::Node.initialize(name, content = nil, namespace = nil) -> XML::Node
 *
 * Creates a new element with the specified name, content and
 * namespace. The content and namespace may be nil.
 */
static VALUE rxml_node_initialize(int argc, VALUE *argv, VALUE self)
{
  VALUE name;
  VALUE content;
  VALUE ns;
  xmlNodePtr xnode = NULL;
  xmlNsPtr xns = NULL;

  rb_scan_args(argc, argv, "12", &name, &content, &ns);

  name = check_string_or_symbol(name);

  if (!NIL_P(ns))
    Data_Get_Struct(ns, xmlNs, xns);

  xnode = xmlNewNode(xns, (xmlChar*) StringValuePtr(name));
  xnode->_private = (void*) self;
  DATA_PTR( self) = xnode;

  if (!NIL_P(content))
    rxml_node_content_set(self, content);

  return self;
}
Esempio n. 3
0
 * call-seq:
 *    attributes.get_attribute_ns("namespace", "name") -> XML::Attr
 * 
 * Returns the specified attribute.
 * 
 * namespace: The URI of the attribute's namespace.
 * name: The name of the attribute, not including a namespace.
 *
 *  doc.root.attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
 */
static VALUE
rxml_attributes_get_attribute_ns(VALUE self, VALUE namespace, VALUE name) {
  xmlNodePtr xnode;
  xmlAttrPtr xattr;

  name = check_string_or_symbol(name);
  
  Data_Get_Struct(self, xmlNode, xnode);
  
  xattr = xmlHasNsProp(xnode, (xmlChar*)StringValuePtr(name), (xmlChar*)StringValuePtr(namespace));
  
  if (xattr)
    return(rxml_attr_wrap(xattr));
  else
    return(Qnil);
}

/*
 * call-seq:
 *    attributes["name"] -> String
 *