Skip to main content

XML_Document.at

atkey

Group: Selections

Documentation

Gets a child or attribute of an XML document.

Arguments

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

Get the first child of the document (the root element).

      XML_Document.from_text '<foo><baz>hello</baz></foo>' . at 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