Skip to content

php通用xml解析类

使用代码,文件名:test_xml_parser.php

<HTML>
<HEAD>
<TITLE>Test for Manuel Lemos’s XML parser PHP class</TITLE>
</HEAD>
<BODY>
<H1><CENTER>Test for Manuel Lemos’s XML parser PHP class</CENTER></H1>
<HR>
<?
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 "&lt;".$structure[$path]["Tag"]."&gt;";
for($element=0;$element<$structure[$path]["Elements"];$element++)
DumpStructure($structure,$positions,$path.",$element");
echo "&lt;/".$structure[$path]["Tag"]."&gt;";
}
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</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>

+++++++++++++++++++++++++++++++++++++++++++++++++
测试结果如下图:

+++++++++++++++++++++++++++++++++++++++++++++++++

下载完整的php通用xml解析类:php-xmlparser

php xml(4)php XML 解析 中文(1)php xml解析类(14)xml php 解析类(2)php xml array 类(1)zend framework parse XML(1)php xml to array(5)php xml array(9)php xml 解析(13)php xml解析(5)php xml 解析类(21)php xml Indent(1)XML php(1)php xml feed parser(1)xml path cache(1)

Share in Google Reader Share in Google Reader 分享到 FriendFeed 分享到 FriendFeed 推荐到豆瓣 推荐到豆瓣 分享到 Twitter 分享到 Twitter

3 Comments

  1. 沙发~

    Posted on 17-Sep-08 at 10:46 pm | Permalink
  2. 不错不错..
    看不懂而已..
    因为PHP和我不熟~

    Posted on 17-Sep-08 at 10:47 pm | Permalink
  3. 我个人比较倾向正则表达式解析。

    Posted on 06-Jun-09 at 3:12 pm | Permalink

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*