Skip to main content

XML_Element.get

getkeyif_missing

Group: Selections

Documentation

Gets a child 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.
  • 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"