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"?>
<body>Don't forget me this weekend!</body>

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"):


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

<body>Don't forget me this weekend!</body>

The last line defines the end of the root element:


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:


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


DOM node tree

The upper panel shows the following XML in a book:

<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>

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