Home > Backend Development > XML/RSS Tutorial > XML tree structure

XML tree structure

黄舟
Release: 2017-02-13 15:30:28
Original
1588 people have browsed it

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&#39;t forget me this weekend!</body>
</note>
Copy after login

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>
Copy after login

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&#39;t forget me this weekend!</body>
Copy after login

The last line defines the end of the root element:

</note>
Copy after login

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>
Copy after login

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:

XML tree structure

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>
Copy after login

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)!

Related labels:
xml
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template