Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.0.0RC3

Bug #2457 extra empty entries in root object tree
Submitted: 2004-10-05 08:44 UTC
From: piro at evodesign dot net Assigned:
Status: Duplicate Package: XML_Tree
PHP Version: 4.3.8 OS: linux
Roadmaps: (Not assigned)    
Subscription  


 [2004-10-05 08:44 UTC] piro at evodesign dot net
Description: ------------ i have the following xml file: <test> <Object name="user" table="user"> <id name="id" column="id" type="int"/> <property name="user_name" column="user_name" type="varchar"/> <property name="first_name" column="first_name" type="varchar"/> </Object> </test> and i'm getting the following structure which is containing empty objects,(2,4,6) children of the <object>: xml_tree_node Object ( [attributes] => Array ( [name] => user [table] => user ) [children] => Array ( [0] => xml_tree_node Object ( [attributes] => Array ( ) [children] => Array ( ) [content] => [name] => [namespaces] => Array ( ) [error] => [use_cdata_section] => [lineno] => 5 ) [1] => xml_tree_node Object ( [attributes] => Array ( [name] => id [column] => id [type] => int ) [children] => Array ( ) [content] => [name] => id [namespaces] => Array ( ) [error] => [use_cdata_section] => [lineno] => 5 ) [2] => xml_tree_node Object ( [attributes] => Array ( ) [children] => Array ( ) [content] => [name] => [namespaces] => Array ( ) [error] => [use_cdata_section] => [lineno] => 6 ) [3] => xml_tree_node Object ( [attributes] => Array ( [name] => user_name [column] => user_name [type] => varchar ) [children] => Array ( ) [content] => [name] => property [namespaces] => Array ( ) [error] => [use_cdata_section] => [lineno] => 6 ) [4] => xml_tree_node Object ( [attributes] => Array ( ) [children] => Array ( ) [content] => [name] => [namespaces] => Array ( ) [error] => [use_cdata_section] => [lineno] => 7 ) [5] => xml_tree_node Object ( [attributes] => Array ( [name] => first_name [column] => first_name [type] => varchar ) [children] => Array ( ) [content] => [name] => property [namespaces] => Array ( ) [error] => [use_cdata_section] => [lineno] => 7 ) ) [content] => [name] => Object [namespaces] => Array ( ) [error] => [use_cdata_section] => [lineno] => 4 )

Comments

 [2004-10-18 07:22 UTC] jmizher at redbaronconsulting dot com
I was able to fix this by commenting out line number 290 in the file 'Tree.php': $parent->children[] = &new XML_Tree_Node(null, $this->cdata, null, $lineno); The line is in the 'startHandler' function. This was using PHP 4.3.8 and XML_Tree 2.0.0RC2.
 [2004-12-13 19:08 UTC] ppslim at gmail dot com
I have just taken this up in #pear on efnet to get a little more detail on the problem and look for a work around. I soon found this isn't a bug but the intended representation. If you look more closely at your original XML_Tree object, you will see that there is also anothe empty child above the "Object" node. The reason for this is that the line breaks between nodes are quite rightly counted as CDATA. The "content" property of the empty object is a newline. It is down to your own application to account for this. Call it a functionality quirk that needs accounting for.
 [2004-12-15 20:05 UTC] aaron dot hawley at uvm dot edu
 [2004-12-20 21:50 UTC] aaron dot hawley at uvm dot edu
I don't object to XML_Tree now being sensitive to all CDATA entries in an XML file. I would just like to see the XML_Tree methods get() and dump() to be considerate of this new situation (what commenter `ppslim' calls a "functionality quirk"). An example is below. Given the following text file: <?xml version="1.0"?> <text> <para>File contents are <emph>great</emph>! Don't you think?</para> </text> passing it through XML_Tree gives: <text> <para> File contents are <emph>great</emph> ! Don&apos;t you think? </para> </text> This is hardly data preservation, because besides the file being outputted not being equivalent to the one given, now there's whitespace between punctuation and a word. Here's the relevant code: require 'XML/Tree.php'; $tree = new XML_Tree('text.xml'); $root = $tree->getTreeFromFile(); $root->dump();
 [2005-07-26 19:34 UTC] ed dot zwart at gmail dot com
Wanting a quick solution that works, I tried jmizher's suggestion of commenting out the line in startHandler(). It worked. I don't really have enough experience with XML, cdata and the like, to immediately know why this solution is okay, but it screams of overkill. Surely there must be times when I'll want cdata. So, instead I simply wrapped the line with if (trim($this->cdata)) { $parent->children[] = ... } which assumes that I'll never want whitespace-only cdata. Can those who know more about this than me comment on the feasability of this solution? Thanks..