Bug #16952: Bug when parsing XML file using XML_Tree

From: Date: Wed, 01 May 2002 20:57:45 +0000
Subject: Bug #16952: Bug when parsing XML file using XML_Tree
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-5941@lists.php.net to get a copy of this message
From: jmcastagnetto@php.net Operating system: RH Linux 6.1 PHP version: 4.2.0 PHP Bug Type: PEAR related Bug description: Bug when parsing XML file using XML_Tree Was testing XML_Tree parsing some files from the PHPDOC directory (the PHP Documentation in cvs.php.net/cvs.php/phpdoc), and found out a really nasty bug that makes this class less than useful. It seems like XML_Tree (or XML_Parser, I had not isolated the problem), just misses content when parsing the files. I used the following code: === testTree.php === require_once "XML/Tree.php"; // change to wherever you have checked out phpdoc $phpdoc = "/home/jesus/devel/php/phpdoc/"; $entities = "entities/global.ent"; $file = "en/language/control-structures.xml"; $xmlarr = file($phpdoc.$file); $entarr = file($phpdoc.$entities); $doctype = '<!DOCTYPE chapter PUBLIC "-//Norman Walsh//DTD DocBk XML V3.1.4/EN" "http://nwalsh.com/docbook/xml/3.1.4/db3xml.dtd" [ '.implode("",$entarr)."\n]>\n"; $xmltop = $xmlarr[0]; $xmlbody = implode("",array_slice($xmlarr,1)); $xmldoc = $xmltop.$doctype.$xmlbody; //echo $xmldoc; $tree = new XML_Tree(); $root = $tree->getTreeFromString($xmldoc); //$root->dump(); print_r($root); === end === And when I run it, I get bits like (when commenting out $root->dump()): === $root->dump() === ... <sect1 id="function.include-once"> <title> <function> include_once</function> </title> <para> <function> The include_once</function> <function>include</function> </para> ... === end === When echoing $xmldoc above, that same section looks like: === echo $xmldoc; === ... <sect1 id="function.include-once"> <title><function>include_once</function></title> <para> The <function>include_once</function> statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the <function>include</function> statement, with the only difference being that if the code from a file has already been included, it will not be included again. As the name suggests, it will be included just once. </para> ... === end === Clearly something went terribly wrong while parsing or constructing the tree. Adding the code below assured me that the xml parsing lib (expat) was not the one messing up: === extra code === $xml = xml_parser_create(); xml_parse_into_struct($xml, $xmldoc, &$vals, &$index); xml_parser_free($xml); print_r($vals); === end === That bit of code got the content OK. I think that a thorough revision of XML_Tree and/or XML_Parser is warranted. -- Edit bug report at http://bugs.php.net/?id=16952&edit=1 -- Fixed in CVS: http://bugs.php.net/fix.php?id=16952&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=16952&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=16952&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=16952&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=16952&r=support Expected behavior: http://bugs.php.net/fix.php?id=16952&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=16952&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=16952&r=submittedtwice

« previous php.pear.dev (#5941) next »