Tuesday, May 29, 2007

XML Reader

Download Source - 8 KB

This sample indicate how to parse XML file using PHP

Sample Code

<?php
require_once("xmllib.php");
$menufilename= "SampleFile.Xml";
$xml =& new XmlLib_xmlParser($menufilename);
$doc =& $xml->getDocument();
$Maindoc=$doc->children[0];
//$arr = $Maindoc->children[$i]->toArray();
if ($Maindoc->hasChildren())
{
       foreach($Maindoc->children as $group)
      {
            echo'id : '.$group->attributes['id'].' Title :'.$group->attributes['title']."<br>";
           if ($group->hasChildren())
           {
                 foreach($group->children as $menuItem)
                {
                     echo'id : '.$menuItem->attributes['id'].' Title : '.$menuItem->attributes['title']."";
                } echo '<br>';
           }
     }
}
?>


No comments: