XML_Element.get
getkeyif_missing
Group: Selections
Documentation
Gets a child 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.if_missing
: The value returned if the key does not exist.
Examples
XML_Document.from_text 'hello ' . root_element . get 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 . get "@bar"
# => "one"