XML Data

Top  Previous  Next

XML is, by nature, structured hierarchically; data is placed between the tags, and all tags have a parent tag except the root tag.

When working with dynamic pages, it is required that you know the hierarchical structure and the tags used in the XML.

A simple XML file

 <?xml version="1.0" encoding="UTF-8"?>

 <root>

  <Name>John</Name>

  <Surname>Smith</Surname>

  </root>

 
A XML document consists of XML Nodes. For example "Name" is an XML node which has starting tag <Name>, data "John" and a closing tag "</Name>"

XML is self explanatory

It is obvious what kind of data is included between the <Name> and <Surname> tags.  This is the power of the XML; it includes both the data description and the data itself.

The Hierarchical Structure

 <?xml version="1.0" encoding="UTF-8"?>

 <root>

  <cd_writers>

    <item>

      <Price>$200</Price>

      <Desc>CD Writer</Desc>

    </item>

    <item>

      <Price>$150</Price>

      <Name>Bony</Name>

      <Desc>CD Writer</Desc>

    </item>

    <item>

      <Price>$50</Price>

      <Name>Tamaha</Name>

      <Desc>CD Writer</Desc>

    </item>

  </cd_writers>

  </root>

 
In the XML above, to query the price of an item, one has to know the parents of the <Price> which are:

<root><cd_writers><item>