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!
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) {
Obtain this attribute’s child attribute(s).
/* * 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.
/* * 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
/* * 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) {
Obtain the last attribute.
/* * call-seq: * attr.last -> node * * Obtain the last attribute. */ VALUE ruby_xml_attr_last_get(VALUE self) {
Determine whether this is the last attribute.
/* * 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.
/* * call-seq: * attr.name -> "name" * * Obtain this attribute's name. */ VALUE ruby_xml_attr_name_get(VALUE self) {
Obtain the next attribute.
/* * call-seq: * attr.next -> node * * Obtain the next attribute. */ VALUE ruby_xml_attr_next_get(VALUE self) {
Determine whether there is a next attribute.
/* * 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.
/* * call-seq: * attr.type_name -> "attribute" * * Obtain this attribute node's type name. */ VALUE ruby_xml_attr_node_type_name(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 this attribute node’s parent.
/* * 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.
/* * 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.
/* * 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) {
Removes this attribute from it’s parent.
/* * call-seq: * node.remove! -> nil * * Removes this attribute from it's parent. */ VALUE ruby_xml_attr_remove_ex(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
Obtain the value of this attribute.
/* * call-seq: * attr.value -> "value" * * Obtain the value of this attribute. */ VALUE ruby_xml_attr_value_get(VALUE self) {