Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

XML Example


XML documents create a hierarchical structure looks like a tree so it is known as XML Tree that starts at “the root” and branches to “the leaves”.

Example of XML Document

XML documents uses a self-describing and simple syntax:

  1. <?xml version=“1.0” encoding=“ISO-8859-1”?>
  2. <note>
  3.   <to>Tove</to>
  4.   <from>Jani</from>
  5.   <heading>Reminder</heading>
  6.   <body>Don’t forget me this weekend!</body>
  7. </note>

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

The next line describes the root element of the document (like saying: “this document is a note”):

  1. <note>

The next 4 lines describe 4 child elements of the root (to, from, heading, and body).

  1. <to>Tove</to>
  2. <from>Jani</from>
  3. <heading>Reminder</heading>
  4. <body>Don’t forget me this weekend!</body>

And finally the last line defines the end of the root element.

  1. </note>

XML documents must contain a root element. This element is “the parent” of all other elements.

The elements in an XML document form a document tree. The tree starts at the root and branches to the lowest level of the tree.

All elements can have sub elements (child elements).

  1. <root>
  2.   <child>
  3.     <subchild>…..</subchild>
  4.   </child>
  5. </root>

The terms parent, child, and sibling are used to describe the relationships between elements. Parent elements have children. Children on the same level are called siblings (brothers or sisters).

All elements can have text content and attributes (just like in HTML).

  1. <bookstore>
  2.   <book category=“COOKING”>
  3.     < The title lang=“en”>Everyday Italian</title>
  4.     <author>Giada De Laurentiis</author>
  5.     <year>2005</year>
  6.     <price>30.00</price>
  7.   </book>
  8.   <book category=“CHILDREN”>
  9.     <title lang=“en”>Harry Potter</title>
  10.     <author>J K. Rowling</author>
  11.     <year>2005</year>
  12.     <price>29.99</price>
  13.   </book>
  14.   <book category=“WEB”>
  15.     <title lang=“en”>Learning XML</title>
  16.     <author>Erik T. Ray</author>
  17.     <year>2003</year>
  18.     <price>39.95</price>
  19.   </book>
  20. </bookstore>

The root element in the example is . All elements in the document are contained within .

The <book> element has 4 children: <title>,< author>, <year>, <price>.

Comments

comments