Cheap VPS & Xen Server

Residential Proxy Network - Hourly & Monthly Packages

XML Tree


An XML document has a self descriptive structure. It forms a tree structure which is referred as an XML tree. The tree structure makes easy to describe an XML document.

A tree structure contains root element (as parent), child element and so on. It is very easy to traverse all succeeding branches and sub-branches and leaf nodes starting from the root.


Example of an XML document

  1. <?xml version=“1.0”?>
  2. <college>
  3.   <student>
  4.       <firstname>Tamanna</firstname>
  5.       <lastname>Bhatia</lastname>
  6.       <contact>09990449935</contact>
  7.       <email>tammanabhatia@abc.com</email>
  8.       <address>
  9.            <city>Ghaziabad</city>
  10.            <state>Uttar Pradesh</state>
  11.            <pin>201007</pin>
  12.       </address>
  13.   </student>
  14. </college>

Test it Now

Let’s see the tree-structure representation of the above example.

xml-tree

In the above example, first line is the XML declaration. It defines the XML version 1.0. Next line shows the root element (college) of the document. Inside that there is one more element (student). Student element contains five branches named <firstname>, <lastname>, <contact>, <Email> and <address>.

<address> branch contains 3 sub-branches named <city>, <state> and <pin>.

Note: DOM parser represents the XML document in Tree structure.

XML Tree Rules

These rules are used to figure out the relationship of the elements. It shows if an element is a child or a parent of the other element.

Descendants: If element A is contained by element B, then A is known as descendant of B. In the above example “College” is the root element and all the other elements are the descendants of “College”.

Ancestors: The containing element which contains other elements is called “Ancestor” of other element. In the above example Root element (College) is ancestor of all other elements.

Comments

comments