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

snippet
<?xml version="1.0"?>
<college>
  <student>
      <firstname>Tamanna</firstname>
      <lastname>Bhatia</lastname>
      <contact>09990449935</contact>
      <email>tammanabhatia@abc.com</email>
      <address>
           <city>Ghaziabad</city>
           <state>Uttar Pradesh</state>
           <pin>201007</pin>
      </address>
  </student>
</college>

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
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.

Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +