Class LibXML::XML::Attributes
In: ext/libxml/libxml.c
lib/libxml/attributes.rb
lib/libxml/properties.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'

Methods

[]   []=   each   each_attr   each_sibling   first   get_attribute   get_attribute_ns   length   node   to_h  

Included Modules

Enumerable

Public Instance methods

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'

[Source]

/*
 * 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'

[Source]

/*
 * 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}

[Source]

/*
 * 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) {

each_attr()

Alias for each

each_sibling()

Alias for each

Returns the first attribute.

 doc.root.attributes.first

[Source]

/*
 * 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")

[Source]

/*
 * 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')

[Source]

/*
 * 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

[Source]

/*
 * call-seq:
 *    attributes.length -> Integer
 * 
 * Returns the number of attributes.
 *
 *  doc.root.attributes.length
 */
VALUE
ruby_xml_attributes_length(VALUE self) {

Return the node that owns this attributes list.

 doc.root.attributes.node == doc.root

[Source]

/*
 * call-seq:
 *   attributes.node -> XML::Node
 * 
 * Return the node that owns this attributes list.
 *
 *  doc.root.attributes.node == doc.root
 */
VALUE
ruby_xml_attributes_node_get(VALUE self) {

[Source]

    # File lib/libxml/attributes.rb, line 7
 7:       def to_h
 8:         inject({}) do |hash, attr|
 9:           hash[attr.name] = attr.value
10:           hash
11:         end
12:       end

[Validate]