Class | LibXML::XML::Attributes |
In: |
ext/libxml/libxml.c
lib/libxml/attributes.rb |
Parent: | Object |
Provides access to an elements attributes (XML::Attr).
Basic Usage:
require 'libxml' doc = XML::Document.new(<some_file>) attributes = doc.root.attributes attributes.each do |attribute| .. end attributes['foo'] = 'bar' attribute = attributes.get_attribute['foo'] attribute.value == 'foo'
To access a namespaced attribute:
XLINK_URI = 'http://www.w3.org/1999/xlink' attribute = attributes.get_attribute_ns(XLINK_URI, 'title') attribute.value = 'My title'
Fetches an attribute value. If you want to access the underlying Attribute itself use get_attribute.
name: The name of the attribute, not including any namespaces.
doc.root.attributes['att'] -> 'some value'
/* * call-seq: * attributes["name"] -> String * * Fetches an attribute value. If you want to access the underlying * Attribute itself use get_attribute. * * name: The name of the attribute, not including any namespaces. * * doc.root.attributes['att'] -> 'some value' */ VALUE ruby_xml_attributes_attribute_get(VALUE self, VALUE name) {
Sets an attribute value. If you want to get the Attribute itself, use get_attribute.
name: The name of the attribute, not including any namespaces. value: The new value of the namespace.
doc.root.attributes['att'] = 'some value'
/* * call-seq: * attributes["name"] = "value" * * Sets an attribute value. If you want to get the Attribute itself, * use get_attribute. * * name: The name of the attribute, not including any namespaces. * value: The new value of the namespace. * * doc.root.attributes['att'] = 'some value' */ VALUE ruby_xml_attributes_attribute_set(VALUE self, VALUE name, VALUE value) {
Iterates over each attribute.
doc.root.attributes.each {|attribute| puts attribute.name}
/* * call-seq: * attributes.each {block} -> XML::Attr * * Iterates over each attribute. * * doc.root.attributes.each {|attribute| puts attribute.name} */ VALUE ruby_xml_attributes_each(VALUE self) {
Returns the first attribute.
doc.root.attributes.first
/* * call-seq: * attributes.first -> XML::Attr * * Returns the first attribute. * * doc.root.attributes.first */ VALUE ruby_xml_attributes_first(VALUE self) {
Returns the specified attribute.
name: The name of the attribute, not including a namespace.
doc.root.attributes.get_attribute("foo")
/* * 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") */ VALUE ruby_xml_attributes_get_attribute(VALUE self, VALUE name) {
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')
/* * 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') */ VALUE ruby_xml_attributes_get_attribute_ns(VALUE self, VALUE namespace, VALUE name) {
Returns the number of attributes.
doc.root.attributes.length
/* * call-seq: * attributes.length -> Integer * * Returns the number of attributes. * * doc.root.attributes.length */ VALUE ruby_xml_attributes_length(VALUE self) {