XML_Document.at
atkey
Group: Selections
Documentation
Gets a child or attribute of an XML document.
Arguments
key: If anInteger, returns the element at positionatin its list of children. If aText, treatskeystarts with"@", returns the attribute with the given name otherwise returns the first child element with the given name.if_missing: The value returned if the key does not exist.
Examples
Get the first child of the document (the root element).
XML_Document.parse '<foo><baz>hello</baz></foo>' . at 0
# => XML_Document.parse "<foo><baz>hello</baz></foo>" . root_element
Get the child of the document (the root element) by name.
root = XML_Document.parse '<foo bar="one">hello</foo>' . get "foo"
# => XML_Document.parse "<foo><baz>hello</baz></foo>" . root_element