XML_Element.at
atkey
Group: Selections
Documentation
Gets a child or attribute of an XML element.
Arguments
key
: If anInteger
, returns the element at positionat
in its list of children. If aText
, ifkey
starts with"@"
, returns the attribute with the given name otherwise returns the first child element with the given name.
Examples
Get a nested tag:
XML_Document.from_text '<foo><baz>hello</baz></foo>' . root_element . at 0
# => XML_Document.from_text "<baz>hello</baz>" . root_element
Get a tag attribute.
root = XML_Document.from_text '<foo bar="one">hello</foo>' . root_element
root.at "@bar"
# => "one"