The XML document forms a tree structure that starts at the root and then expands to the foliage.
An instance of an XML document
XML uses simple, self-describing syntax:
<?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>George</to> <from>John</from>
The first line is the XML declaration. It defines the version (1.0) of the XML and the encoding used (iso-8859-1 = latin-1/Western Character set).
The next line describes the root element of the document (like, "This document is a sticky note"):
<note>
The next 4 lines describe the 4 child elements of the root (to, from, heading, and body):
<to>George</to> <from>John</from>
The last line defines the end of the root element:
</note>
From this example, it is conceivable that the XML document contains a note by John to George.
Do you agree that XML has excellent self-describing nature?
XML documents form a tree structure
The XML document must contain a root element. The element is the parent element of all other elements.
Elements in an XML document form a tree of documents. The tree begins at the root and expands to the bottom of the tree.
All elements can have child elements:
<root> <child> <subchild>.....</subchild> </child> </root>
The terms parent, child, and sibling are used to describe the relationship between elements. The parent element has child elements. Child elements at the same level become compatriots (brothers or sisters).
All elements can have textual content and attributes (similar to HTML).
Instance
The figure above 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">LearningXML</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 included in <bookstore>.
<book> element has 4 child elements:<title>, < author>, <year>, <price>.