XML_Document.get
getkeyif_missing
Group: Selections
Documentation
Gets a child element of an XML document.
Arguments
key
: If anInteger
, returns the element at positionat
in its list of children. IfText
, then if starts with"@"
, returns the attribute with the given name otherwise returns the first child element with the given name.
Examples
Get the first child of the document (the root element).
XML_Document.from_text '<foo><baz>hello</baz></foo>' . get 0
# => XML_Document.from_text "<foo><baz>hello</baz></foo>" . root_element
Get the child of the document (the root element) by name.
root = XML_Document.from_text '<foo bar="one">hello</foo>' . get "foo"
# => XML_Document.from_text "<foo><baz>hello</baz></foo>" . root_element