Skip to main content

XML_Element.at

atkey

Group: Selections

Documentation

Gets a child or attribute of an XML element.

Arguments

  • key: If an Integer, returns the element at position at in its list of children. If a Text, if key 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"