Home Php XML Expat Library:



XML Expat Library:
Posted on: November 23, 2009 at 12:00 AM
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
        )

)
  

Related Tags for XML Expat Library::


More Tutorials from this section

Ask Questions?    Discuss: XML Expat Library:  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.