Class LibXML::XML::Attr
In: ext/libxml/libxml.c
lib/libxml/attr.rb
Parent: Object

Provides access to an single element attribute. Accessed by calling XML::Node#attributes method.

Basic Usage:

 require 'libxml'

 doc = XML::Document.new(<some_file>)
 attribute = doc.root.attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
 attribute.name == 'href'
 attribute.value == 'http://www.mydocument.com'
 attribute.remove!

Methods

child   child?   doc   doc?   each   each_attr   each_sibling   last   last?   name   new   next   next?   node_type_name   ns   ns?   parent   parent?   prev   prev?   remove!   siblings   to_a   to_h   to_s   value   value=  

Included Modules

Enumerable

Public Class methods

Creates a new attribute for the node.

node: The XML::Node that will contain the attribute name: The name of the attribute value: The value of the attribute

 attr = XML::Attr.new(doc.root, 'name', 'libxml')

[Source]

/*
 * call-seq:
 *    attr.initialize(node, "name", "value")
 * 
 * Creates a new attribute for the node.
 *
 * node: The XML::Node that will contain the attribute
 * name: The name of the attribute
 * value: The value of the attribute
 *
 *  attr = XML::Attr.new(doc.root, 'name', 'libxml')
 */
VALUE
ruby_xml_attr_initialize(int argc, VALUE *argv, VALUE self) {

Public Instance methods

Obtain this attribute’s child attribute(s).

[Source]

/*
 * call-seq:
 *    attr.child -> node
 * 
 * Obtain this attribute's child attribute(s).
 */
VALUE
ruby_xml_attr_child_get(VALUE self) {

Determine whether this attribute has child attributes.

[Source]

/*
 * call-seq:
 *    attr.child? -> (true|false)
 * 
 * Determine whether this attribute has child attributes.
 */
VALUE
ruby_xml_attr_child_q(VALUE self) {

Returns this attribute’s document.

 doc.root.attributes.get_attribute('name').doc == doc

[Source]

/*
 * call-seq:
 *    attr.doc -> XML::Document
 * 
 * Returns this attribute's document.
 *
 *  doc.root.attributes.get_attribute('name').doc == doc
 */
VALUE
ruby_xml_attr_doc_get(VALUE self) {

Determine whether this attribute is associated with an XML::Document.

[Source]

/*
 * call-seq:
 *    attr.doc? -> (true|false)
 * 
 * Determine whether this attribute is associated with an
 * XML::Document.
 */
VALUE
ruby_xml_attr_doc_q(VALUE self) {

each(&blk)

Alias for each_sibling

each_attr(&blk)

Alias for each_sibling

[Source]

    # File lib/libxml/attr.rb, line 19
19:       def each_sibling(&blk)
20:         siblings(self,&blk)
21:       end

Obtain the last attribute.

[Source]

/*
 * call-seq:
 *    attr.last -> node
 * 
 * Obtain the last attribute.
 */
VALUE
ruby_xml_attr_last_get(VALUE self) {

Determine whether this is the last attribute.

[Source]

/*
 * call-seq:
 *    attr.last? -> (true|false)
 * 
 * Determine whether this is the last attribute.
 */
VALUE
ruby_xml_attr_last_q(VALUE self) {

Obtain this attribute’s name.

[Source]

/*
 * call-seq:
 *    attr.name -> "name"
 * 
 * Obtain this attribute's name.
 */
VALUE
ruby_xml_attr_name_get(VALUE self) {

Obtain the next attribute.

[Source]

/*
 * call-seq:
 *    attr.next -> node
 * 
 * Obtain the next attribute.
 */
VALUE
ruby_xml_attr_next_get(VALUE self) {

Determine whether there is a next attribute.

[Source]

/*
 * call-seq:
 *    attr.next? -> (true|false)
 * 
 * Determine whether there is a next attribute.
 */
VALUE
ruby_xml_attr_next_q(VALUE self) {

Obtain this attribute node’s type name.

[Source]

/*
 * call-seq:
 *    attr.type_name -> "attribute"
 * 
 * Obtain this attribute node's type name.
 */
VALUE
ruby_xml_attr_node_type_name(VALUE self) {

Obtain this attribute’s associated XML::NS, if any.

[Source]

/*
 * call-seq:
 *    attr.ns -> namespace
 * 
 * Obtain this attribute's associated XML::NS, if any.
 */
VALUE
ruby_xml_attr_ns_get(VALUE self) {

Determine whether this attribute has an associated namespace.

[Source]

/*
 * call-seq:
 *    attr.ns? -> (true|false)
 * 
 * Determine whether this attribute has an associated 
 * namespace.
 */
VALUE
ruby_xml_attr_ns_q(VALUE self) {

Obtain this attribute node’s parent.

[Source]

/*
 * call-seq:
 *    attr.parent -> node
 * 
 * Obtain this attribute node's parent.
 */
VALUE
ruby_xml_attr_parent_get(VALUE self) {

Determine whether this attribute has a parent.

[Source]

/*
 * call-seq:
 *    attr.parent? -> (true|false)
 * 
 * Determine whether this attribute has a parent.
 */
VALUE
ruby_xml_attr_parent_q(VALUE self) {

Obtain the previous attribute.

[Source]

/*
 * call-seq:
 *    attr.prev -> node
 * 
 * Obtain the previous attribute.
 */
VALUE
ruby_xml_attr_prev_get(VALUE self) {

Determine whether there is a previous attribute.

[Source]

/*
 * call-seq:
 *    attr.prev? -> (true|false)
 * 
 * Determine whether there is a previous attribute.
 */
VALUE
ruby_xml_attr_prev_q(VALUE self) {

Removes this attribute from it’s parent.

[Source]

/*
 * call-seq:
 *     node.remove! -> nil
 * 
 * Removes this attribute from it's parent.
 */
VALUE
ruby_xml_attr_remove_ex(VALUE self) {

Iterates nodes and attributes

[Source]

    # File lib/libxml/attr.rb, line 10
10:       def siblings(node, &blk)
11:         if n = node
12:           loop do
13:             blk.call(n)
14:             break unless n = n.next
15:           end
16:         end 
17:       end

[Source]

    # File lib/libxml/attr.rb, line 33
33:       def to_a
34:         inject([]) do |ary,a| 
35:           ary << [a.name, a.value]
36:           ary
37:         end
38:       end

[Source]

    # File lib/libxml/attr.rb, line 26
26:       def to_h
27:         inject({}) do |h,a|
28:           h[a.name] = a.value
29:           h
30:         end
31:       end

[Source]

    # File lib/libxml/attr.rb, line 40
40:       def to_s
41:         "#{name} = #{value}"
42:       end

Obtain the value of this attribute.

[Source]

/*
 * call-seq:
 *    attr.value -> "value"
 * 
 * Obtain the value of this attribute.
 */
VALUE
ruby_xml_attr_value_get(VALUE self) {

Sets the value of this attribute.

[Source]

/*
 * call-seq:
 *    attr.value = "value"
 * 
 * Sets the value of this attribute.
 */
VALUE
ruby_xml_attr_value_set(VALUE self, VALUE val) {

[Validate]