| 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 'xml'
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!
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')
/*
* 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) {
Returns this attribute‘s document.
doc.root.attributes.get_attribute('name').doc == doc
/*
* 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.
/*
* call-seq:
* attr.doc? -> (true|false)
*
* Determine whether this attribute is associated with an
* XML::Document.
*/
VALUE
ruby_xml_attr_doc_q(VALUE self) {
Determine whether this attribute has an associated namespace.
/*
* call-seq:
* attr.ns? -> (true|false)
*
* Determine whether this attribute has an associated
* namespace.
*/
VALUE
ruby_xml_attr_ns_q(VALUE self) {
Obtain the previous attribute.
/*
* call-seq:
* attr.prev -> node
*
* Obtain the previous attribute.
*/
VALUE
ruby_xml_attr_prev_get(VALUE self) {
Determine whether there is a previous attribute.
/*
* call-seq:
* attr.prev? -> (true|false)
*
* Determine whether there is a previous attribute.
*/
VALUE
ruby_xml_attr_prev_q(VALUE self) {
Iterates nodes and attributes
# 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
# 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
# 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