To interchange the information on the web, XML provides structured, documented data format. It is also a scripting tag language just like HTML but it uses its own tags to manipulate data on the web. The XML parser allows an XML document to be created, read and updated. In fact, parser is a way to interchange information on the web. There are two types of XML parsers:  

  1. Tree-Based Parser
  2. Event-Based Parser

The Tree-Based Parser logically converts the whole xml document into a tree structure and archives this document into its memory. After analyzing the document, it provides the access to its tree. However as it consumes large part of memory it is better suited for small xml documents. 

The Event-Based Parser holds the document in its memory and forms an event based structure. It consumes small part of memory and can handle large xml documents.

Basic example how to read an xml data

    $xmlBody = "<?xml version='1.0' encoding='UTF-8'?>
        <city1>New York</city1>
        <city2>Los Angeles</city2>
    $xml = simplexml_load_string($xmlBody) or die("Cannot create XML object!");

In the example above the output will be:

SimpleXMLElement Object ( [city1]=>NewYork [city2]=>Los Angeles [city3]=>Chicago )


XML tutorial in details may be found here...


›› go to examples ››