An XML document example
The XML document uses a simple self-descriptive 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 4 lines describe the 4 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 written by Jani to Tove.
XML is brilliantly self-describing, 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 picture represents a book in the following XML:
<bookstore> <book category="COOKING"> <title>Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="CHILDREN"> <title>Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="WEB"> <title>Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore>
The above is the content of the XML tree structure, For more related content, please pay attention to the PHP Chinese website (www.php.cn)!