Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Php XML Expat Library:

 
 

Share on Google+Share on Google+

XML Expat Library:

Advertisement
PHP's XML parser is based on Expat. It lets you parse but not validate XML documents means it does not allow us to find out the XML tags which are present instead of that we can check the correctness of the structure.

XML Expat Library:

     

PHP's XML parser is based on Expat. It lets you parse but not validate XML documents means  it does not allow us to find out the XML tags which are present  instead of that we can check  the correctness of  the structure. PHP?s XML parser is event-based. In the following example you could learn about  few in-built functions provided by PHP to access XML document.

Example:

<?php

$xml="<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?><lang><php>PHP is very easy to learn</php><Java>Java is the king of open source language</Java></lang>";

$parse=xml_parser_create();

xml_parse_into_struct($parse,$xml,$var1,$var2);

xml_parser_free($parse);

echo "<b>Index array:</b>"."<br/>";

print_r($var1);

echo "<br/><b>Vals array</b><br/>";

print_r($var2);

?>

Output:

Index array:
Array
(
    [0] => Array
        (
            [tag] => LANG
            [type] => open
            [level] => 1
        )

    [1] => Array
        (
            [tag] => PHP
            [type] => complete
            [level] => 2
            [value] => PHP is very easy to learn
        )

    [2] => Array
        (
            [tag] => JAVA
            [type] => complete
            [level] => 2
            [value] => Java is the king of open source language
        )

    [3] => Array
        (
            [tag] => LANG
            [type] => close
            [level] => 1
        )

)

Vals array
Array
(
    [LANG] => Array
        (
            [0] => 0
            [1] => 3
        )

    [PHP] => Array
        (
            [0] => 1
        )

    [JAVA] => Array
        (
            [0] => 2
        )

)
  
Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 23, 2009

Related Tutorials

Discuss: XML Expat Library:  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com