Latest web development tutorials

XML tree structure

XML documents form a tree structure, which from the "root" and then extended to the "leaves."


An XML document instance

XML documents using a simple self-descriptive syntax:

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

The first line is the XML declaration. It defines the XML version (1.0) and the encoding used (ISO-8859-1 = Latin-1 / Western European character sets).

The next line describesthe root element of the document (like saying: "This document is a memo"):

<note>

The next 4 lines describe 4child elements of the root (to, from, heading, and body):

<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>

The last line defines the end of the root element:

</note>

You can assume, from this example, XML document contains a Jani Tove of written notes.

XML has excellent self descriptive, you agree?


XML documents form a tree structure

XML document must contain aroot element.The element is the parent of all other elements.

XML elements in the document to form a document tree. The tree from the root, and extends to the bottom of the tree.

All elements can have sub-elements:

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

Father, the Son and the like compatriot term used to describe the relationship between elements. The parent element has a child element. Sub-elements on the same level become siblings (brothers or sisters).

All elements can have text content and attributes (similar to the HTML).


Example:

DOM node tree

The upper panel shows the following XML in a book:

<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>

Examples of the root element is <bookstore>. Document all <book> elements are contained within <bookstore> in.

<Book> element has four sub-elements: <title>, <author>, <year>, <price>.