XML Tree

A tree structure is formed by an XML document. It starts at “the root” and branches to “the leaves”.

Example:

Books.xml:

<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
 
  <book category="Child">
    <title lang="en">ABC</title>
    <author>Unknown</author>
    <year>2020</year>
    <price>100.00</price>
  </book>
 
  <book category="IT">
    <title lang="en">XQuery Book</title>
    <author>Author 1</author>
    <author>Author 2</author>
    <author>Author 3</author>
    <author>Author 4</author>
    <year>2004</year>
    <price>350.00</price>
  </book>
 
</bookstore>

Output: XML Tree:

XML Tree Structure:

Formed as element trees, these XML documents as an XML tree start at a root element. It branches from the root to child elements, where any element can have sub-elements or child elements.

Syntax:

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

Here, the information about books in a bookstore are contained in the XML document. To describe the relationships between elements, the parent, child, and sibling terms are used. Parents have children and vice versa. Children on the same level are called Siblings (brothers and sisters). Any element can have text content and attributes.

Self-Describing Syntax:

A much self-describing syntax is used by XML. The XML version and the character encoding is defined by a prolog:

<?xml version="1.0" encoding="UTF-8"?>

The root element is the next line of the document:

<bookstore>

The <book> element is started by the next line:

<book category="Child">

There are 4 child elements in the <book> elements including, <title>, <author>, <year>, <price>:

<title lang="en">ABC</title>
    <author>Unknown</author>
    <year>2020</year>
    <price>100.00</price>

The book element is ended by the next line:

</book>

The XML though is quite self-descriptive, with sender information, receiver information, a heading, and a message body, but still, it does not do anything and is just information wrapped in tags.

Please Share