How to use Tree in XML

In this article I am going to explain about what is XML Tree. XML document in the form of a tree structure.
  • 2415

Introduction

In this article I am going to explain about what is XML Tree. XML document form a tree structure. In tree structure It has a root, then sub root then again sub root of sun root if required in XML Document. XML documents have a hierarchical structure and can conceptually be interpreted as a tree structure, called an XML tree.

Example

Fallowing example is well formed XML Document.

<?xml version="1.0" encoding="utf-8" ?>
<bookstore>
     <book category="sport">
        <title>Cricket Master</title>
        <author>Denish Richchi</author>
        <year>2003</year>
        <price>699</price>     
  </book>
    <book category="music">
        <title>Learning Music</title>
        <author>Javed Akhater</author>
        <year>2003</year>
        <price>999</price>     
  </book>
</bookstore>

Here I am explaining about XML Tree

  • First line in XML document known as XML declaration .
  • Next line in XML document (<bookstore>) is known as root element of XML document.
  • Next line in XML document (<book category="sport">) is known as child element of root element (book store).
  • Next four lines in XML document (title, author, year and price) is known as child elements of element book store.
  • Next four lines in XML document (</book>) define end of <book category="sport">  element.
  • Last line </bookstore> in XML document define end of root element.

XML Documents Form a Tree Structure

XML document must have root element and root element is known as " parent of all elements" in XML document. All element in XML document form a tree structure. This tree start at root element and then sub child of root element.

 <root>
  <child>
    <subchild>.....</subchild>
  </child>
</root>

Further Readings

You may also want to read these related articles :

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.