XML tree

 

XML document form a tree structure, from which "roots" started, and then expand into the "leaves."

An XML document instance

Using a simple XML syntax self-descriptive:

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>

The first line is the XML declaration. It defines the XML version (1.0) and used for encoding (ISO-8859-1 = Latin-1 / Western European character sets).

The next line description of the document root element (as if saying: "This document is a note"):

<note>

Next, four rows of four root described sub-elements (to, from, heading and body):

<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>

The last line defines the end of the root element:

</note>

From this example, it is conceivable that the XML document contains a note of John to George.

XML has excellent self-descriptive, do you agree?

XML documents form a tree structure

XML documents must contain a root element . The element is the parent of all other elements.

XML document elements form a document tree. This tree starts from the root, and extends to the bottom of the tree.

All elements can have sub-elements:

<root>
  <child>
    <subchild>.....</subchild>
  </child>
</root>

Parent, child, and a fellow like terms describe relationships between elements. Parent elements have children. Sub-elements on the same level to be siblings (brothers or sisters).

All elements can have text content and attributes (similar to the HTML).

Examples

The figure 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>

Example is the root element <bookstore>. All <book> elements in the document are included in the <bookstore> in.

<Book> element has four sub-elements: <title>, <author>, <year>, <price>.

Reproduced in: https: //www.cnblogs.com/Codenewbie/archive/2013/04/07/3003654.html

Guess you like

Origin blog.csdn.net/weixin_34184158/article/details/93448193