class Ox::Element

An Element represents a element of an XML document. It has a name, attributes, and sub-nodes.

To access the child elements or attributes there are several options. One is to walk the nodes and attributes. Another is to use the locate() method. The easiest for simple regularly formatted XML is to reference the sub elements or attributes simply by name. Repeating elements with the same name can be referenced with an element count as well. A few examples should explain the ‘easy’ API more clearly.

Example

doc = Ox.parse(%{
<?xml?>
<People>
  <Person age="58">
    <given>Peter</given>
    <surname>Ohler</surname>
  </Person>
  <Person>
    <given>Makie</given>
    <surname>Ohler</surname>
  </Person>
</People>
})

doc.People.Person.given.text
=> "Peter"
doc.People.Person(1).given.text
=> "Makie"
doc.People.Person.age
=> "58"