XML Tree Structure
An XML document forms a tree structure that starts at the \"root\" and expands to the \"branches and leaves\".
An XML document example
XML documents use a simple, self-descriptive syntax:
<
note
<
to
Tove
to
<
from
Jani
from
<
heading
Reminder
heading
<
bodyDon'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 (UTF-8: Unicode, which can display various languages).
The next line describes the document'sRoot element(as if saying: \"This document is a note\"):
The next 4 lines describe the 4Child Elementchild elements of the root (to, from, heading, and body):
<
to
Tove
to
<
from
Jani
from
<
heading
Reminder
heading
<
bodyDon't forget me this weekend!
body
The last line defines the end of the root element:
You can assume that, from this example, the XML document contains a note from Jani to Tove.
XML has excellent self-descriptiveness, don't you agree?
XML documents form a tree structure
An XML document must contain aRoot element. This element is the parent of all other elements.
The elements in an XML document form a document tree. The tree starts at the root and expands to the lowest level of the tree.
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. A parent element has child elements. Child elements at the same level become siblings (brothers or sisters).
All elements can have text content and attributes (similar to HTML).
Example:
The diagram above represents a book in the XML below:
XML document example
<
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
bookstoreThe root element in the example is