<?php
/*
* test_xml_parser.php
*
* @(#) $Id: test_xml_parser.php,v 1.10 2012/09/05 09:27:07 mlemos Exp $
*
*/
?><html>
<head>
<title>Test for Manuel Lemos's XML parser PHP class</title>
</head>
<body>
<h1 align="center">Test for Manuel Lemos's XML parser PHP class</h1>
<hr>
<?php
require("xml_parser.php");
Function DumpArray(&$array,$indent)
{
for(Reset($array),$node=0;$node<count($array);Next($array),$node++)
{
echo $indent."\"".Key($array)."\"=";
$value=$array[Key($array)];
if(GetType($value)=="array")
{
echo "\n".$indent."[\n";
DumpArray($value,$indent."\t");
echo $indent."]\n";
}
else
echo "\"$value\"\n";
}
}
Function DumpStructure(&$structure,&$positions,$path)
{
echo "[".$positions[$path]["Line"].",".$positions[$path]["Column"].",".$positions[$path]["Byte"]."]";
if(GetType($structure[$path])=="array")
{
echo "<".$structure[$path]["Tag"];
if(IsSet($structure[$path]["Attributes"]))
{
$attributes = $structure[$path]["Attributes"];
$ta = count($attributes);
for(Reset($attributes), $a = 0; $a < $ta; Next($attributes), ++$a)
{
$attribute = Key($attributes);
echo " ", $attribute, "=\"", HtmlSpecialChars($attributes[$attribute]), "\"";
}
}
echo ">";
for($element=0;$element<$structure[$path]["Elements"];$element++)
DumpStructure($structure,$positions,$path.",$element");
echo "</".$structure[$path]["Tag"].">";
}
else
echo $structure[$path];
}
$file_name="example.xml";
$error=XMLParseFile($parser,$file_name,1,$file_name.".cache");
if(strcmp($error,""))
echo "<H2><center>Parser error: ".$error." Line: ".$parser->error_line." Column: ".$parser->error_column." Byte index: ".$parser->error_byte_index."</center></H2>\n";
else
{
echo "<H2><center>Parsed file structure</center></H2>\n";
echo "<P>This example dumps the structure of the elements of an XML file by displaying the tags and data preceded by their positions in the file: line number, column number and file byte index.</P>\n";
echo "<PRE>";
DumpStructure($parser->structure,$parser->positions,"0");
echo "</PRE>\n";
}
?></body>
</html>
|