Links Smart Home
Links Script Collections
Links Tutorials
Links Contact
 
 
 
 

Tutorials

 

 

 
  Simple XML Pasrer using php.
//start tag map and endtagmap has to be modified based on our requirement//
$XmlData;
$ParseLevel;
$ErrorInfo;
$ErrorLine;




function GetFileRef($file)
{
if(!file_exists($file))
{
global $ErrorInfo;
global $ErrorLine;

$ErrorInfo[] = "MX : File not found ";
$ErrorLine[] = __LINE__;
return false;
}
else
{
$handler = fopen($file,"r");
$xmldata = fread($handler,filesize($file));
return $xmldata;
}
}

function RaiseException()
{
global $ErrorInfo;
global $ErrorLine;

$errorCount = count($ErrorInfo);
for($i=0;$i<$errorCount;$i++)
{
$error = $ErrorInfo[$i];
$line = $ErrorLine[$i];

echo "MX=>Error =>".$error." =>File=>".$_SERVER['SCRIPT_FILENAME']."=>Line No :".$line."<br>";
}
}

function StartTagMap($parser,$tags)
{
echo "<br>".$tags;

}


function EndTagMap($parser,$tags)
{
echo "<--End Tag Mapper -->";
}

function DataProcMap($parser,$data)
{
echo "$data<br>";
}

function ParseXml($file)
{
$parser = xml_parser_create();

xml_set_element_handler($parser,"StartTagMap","EndTagMap");
xml_set_character_data_handler($parser,"DataProcMap");

if(!GetFileRef($file))
{
RaiseException();
}
else
{
xml_parse($parser,GetFileRef($file));
}

}
   
   
  Back to Index