XML documents form a tree structure that starts at the "root" and extends to the "leaves."
The tree structure is commonly referred to as an XML tree, and can easily describe any XML document.
By using a tree structure, you can know all subsequent branches and sub-branches starting from the root.
XML documents use a simple, self-describing 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 version of XML (1.0) and the encoding used (ISO-8859-1 = Latin-1/Western European character set).
The next line describes the root element of the document (like saying: "This document is a sticky note"):
<note>
The next four lines describe the four child 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 that the XML document contains a note from Jani to Tove. XML is extremely self-descriptive, don't you agree? XML documents form a tree structure. XML documents must contain a root element. This element is the parent element of all other elements. The elements in an XML document form a document tree. The tree starts at the root and expands to the very bottom 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 relationship between elements. Parent elements own 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 above image represents a book in the following XML:
<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>
The root element in the example is <bookstore>. All <book> elements in the document are contained in <bookstore>. The <book> element has 4 child elements: <title>, <author>, <year>, <price>. In the next section, we will explain the syntax of XML.