"DTD/xhtml1-strict.dtd">
A class that defines the set of Attributes of
an Element and provides operations for accessing
elements in that set.
Fetches an attribute value. If you want to get the Attribute itself, use get_attribute ()
name: an XPath attribute name. Namespaces are relevant
here.
Returns: the String value of the matching attribute, or nil if no matching
attribute was found.
doc = Document.new "<a foo:att='1' bar:att='2' att='3'/>"
doc.root.attributes['att'] #-> '3'
doc.root.attributes['bar:att'] #-> '2'
Returns the number of attributes the owning Element contains.
doc = Document "<a x='1' y='2' foo:x='3'/>"
doc.root.attributes.length #-> 3
Itterates over the attributes of an Element .
Yields actual Attribute nodes, not String
values.
doc = Document.new '<a x="1" y="2"/>'
doc.root.attributes.each_attribute {|attr|
p attr.expanded_name+" => "+attr.value
}
Itterates over each attribute of an Element ,
yielding the expanded name and value as a pair of Strings.
doc = Document.new '<a x="1" y="2"/>'
doc.root.attributes.each {|name, value| p name+" => "+value }
Fetches an attribute
name: the name by which to search for the attribute. Can be a
prefix:name namespace name.
Returns: The first matching attribute, or nil if there was none. This
value is an Attribute node, not the String
value of the attribute.
doc = Document.new '<a x:foo="1" foo="2" bar="3"/>'
doc.root.attributes.get_attribute("foo").value #-> "2"
doc.root.attributes.get_attribute("x:foo").value #-> "1"
Sets an attribute, overwriting any existing attribute value by the same
name. Namespace is significant.
name: the name of the attribute
value: (optional) If supplied, the value of the attribute. If nil, any existing
matching attribute is deleted.
Returns: Owning element
doc = Document.new "<a x:foo='1' foo='3'/>"
doc.root.attributes['y:foo'] = '2'
doc.root.attributes['foo'] = '4'
doc.root.attributes['x:foo'] = nil
Returns an array of Strings containing all of the prefixes declared by this
set of # attributes. The array does not include the default namespace
declaration, if one exists.
"z='glorp' p:k='gru'/>")
prefixes = doc.root.attributes.prefixes #-> ['x', 'y']
Removes an attribute
attribute: either a String, which is the name of the attribute to remove -- namespaces
are significant here -- or the attribute to remove.
Returns: the owning element
doc = Document.new "<a y:foo='0' x:foo='1' foo='3' z:foo='4'/>"
doc.root.attributes.delete 'foo' #-> <a y:foo='0' x:foo='1' z:foo='4'/>"
doc.root.attributes.delete 'x:foo' #-> <a y:foo='0' z:foo='4'/>"
attr = doc.root.attributes.get_attribute('y:foo')
doc.root.attributes.delete attr #-> <a z:foo='4'/>"
Adds an attribute, overriding any existing attribute by the same name.
Namespaces are significant.
Deletes all attributes matching a name. Namespaces are significant.
name: A String; all attributes that match this path will be removed
Returns: an Array of the Attributes that were removed