XML Tree Structure
- Previous Page XML Usage
- Next Page XML Syntax
An XML document forms a tree structure, starting from the 'root' and then expanding to the 'leaves'.
XML Tree Structure

XML Document Example
This XML represents the book list:
<?xml version="1.0" encoding="UTF-8"?> <bookstore> <book category="美食"> <title lang="zh">雅舍谈吃</title> <author>梁实秋</author> <press>江苏文艺出版社</press> <year>2013</year> <price>35</price> <ISBN>9787539962771</ISBN> </book> <book category="儿童"> <title lang="zh">了不起的狐狸爸爸</title> <author>罗尔德·达尔</author> <translator>代维</translator> <press>明天出版社</press> <year>2009</year> <price>10</price> <ISBN>9787533259563</ISBN> </book> <book category="文学"> <title lang="zh">将熟悉变为陌生</title> <author>齐格蒙·鲍曼</author> <author>彼得·哈夫纳</author> <translator>王立秋</translator> <press>南京大学出版社</press> <year>2023</year> <price>68</price> <ISBN>9787305269387</ISBN> </book> <book category="科学"> <title lang="zh">你想飞吗,像鸟一样?</title> <author>Richard Dawkins</author> <author>Yana Renzova</author> <translator>High Tianyu</translator> <press>Hunan Science and Technology Press</press> <year>2023</year> <price>88</price> <ISBN>9787571019075</ISBN> </book> <book category="politics" cover="softcover"> <title lang="en">Democracy in America</title> <author>de Tocqueville</author> <translator>Dong Guoliang</translator> <press>Shangwu Yinshe</press> <year>1989</year> <price>60</price> <ISBN>9787100124553</ISBN> </book> </bookstore>
XML Tree Structure
The elements in an XML document form aelement tree.
This tree starts fromRoot elementbegin, and extend to theChild elements.
An XML document must contain a root element. This element is the parent of all other elements.
All elements can have child elements:
<root> <child> <subchild>.....</subchild> </child> </root>
Terms such as parent, child, and sibling are used to describe the relationships between elements.
Parent elements have child elements. Child elements also have parent elements. Child elements at the same level are siblings (brothers or sisters).
All elements can have text content (like 'Ya She Talks About Eating') and attributes (category="food"), similar to HTML.
Self-descriptive syntax
XML uses a simple self-descriptive syntax:
<?xml version="1.0" encoding="UTF-8"?> <note> <to>George</to> <from>John</from> <heading>Reminder</heading> <body>Don't forget the meeting!</body> </note>
The first line is an XML declaration. It defines the version of XML (1.0) and the encoding used (ISO-8859-1 = Latin-1/Western character set).
The next line describes the document:Root element(like saying: 'This document is a note'):
<note>
The next 4 lines describe the root: 4 sub-elements(to, from, heading as well as body):
<to>George</to> <from>John</from> <heading>Reminder</heading> <body>Don't forget the meeting!</body>
The last line defines the end of the root element:
</note>
From this example, it can be imagined that the XML document contains a note from John to George.
XML has excellent self-descriptive capabilities, do you agree?
- Previous Page XML Usage
- Next Page XML Syntax