Defining the XML Tree
- XML documents must contain a root element. This element is "the parent" of all other elements
- The elements in an XML document form a document tree
- The tree starts at the root and branches to the lowest level of the tree
- All elements can have sub elements (child elements):
<root>
<child>
<subchild> ……. </subchild>
</child>
</root>
- The terms parent, child and sibling are used to describe the relationships between elements. Parent elements have children. Children on the same level are called siblings (brothers or sisters)
- All elements can have text content and attributes (just like in HTML)
<bookstore>
<book category="CHILDREN">
<title lang="en">Harry Potter </title>
<author>J K. Rowling</author>
<year>2006</year>
<price>49.65</price>
</book>
<book
category="WEB">
<title lang="en">WT</title>
<author>chris bates</author>
<year>2005</year>
<price>30.00</price>
</book>
</bookstore>
- The root element in the example is <bookstore>
- All <book> elements in the document are contained within <bookstore>
- The <book> element has 4 children: <title>, < author>, <year>, <price>