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:


  Tove
  Jani
  Reminder
  Don't forget me this weekend!


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"):


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

Tove
Jani
Reminder
Don't forget me this weekend!

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


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


  
    .....
  


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

Another Example of XML: Books

File: books.xml


  
    Everyday Italian
    Giada De Laurentiis
    2005
    30.00
  
  
    Harry Potter
    J K. Rowling
    2005
    29.99
  
  
    Learning XML
    Erik T. Ray
    2003
    39.95
  

Test it Now

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

The element has 4 children: