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

Bug #492 character data content at the end of root element is ignored
Submitted: 2003-12-24 22:44 UTC
From: chris_se at gmx dot net Assigned: davey
Status: Closed Package: XML_Tree
PHP Version: Irrelevant OS: All
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 1 + 34 = ?

 
 [2003-12-24 22:44 UTC] chris_se at gmx dot net
Description: ------------ If you have an XML-File with character data at the end of the root element, this character data will be ignored. Please note that this will not occur, if there is any other xml element *after* the character data. It only occurs, if the character data is at the end of the root element. Version: $Id: Tree.php,v 1.31 2003/09/18 10:51:34 cox Exp $ The following patch will solve the problem: --- Tree-old.php 2003-12-24 23:39:01.000000000 +0100 +++ Tree.php 2003-12-24 23:39:14.000000000 +0100 @@ -303,6 +303,15 @@ $parent =& $this->$parent_id; // attach the node to its parent node children array $parent->children[] = $node; + } else { + $node =& $this->obj1; + if (count($node->children) > 0) { + if (trim($this->cdata)) { + $node->children[] = &new XML_Tree_Node(null, $this->cdata); + } + } else { + $node->setContent($this->cdata); + } } $this->cdata = null; return null; Reproduce code: --------------- parser.php: <?php require 'XML/Tree.php'; $tree = new XML_Tree ('data.xml'); $tree->getTreeFromFile (); $tree->dump (); ?> data.xml: <?xml version="1.0" encoding="iso-8859-1"?> <root> content </root> Expected result: ---------------- <?xml version="1.0"?> <root>content</root> Actual result: -------------- <?xml version="1.0"?> <root></root>

Comments

 [2004-05-19 11:31 UTC] davey
Added to the Uber patch. Thank you for your contribution :) - Davey
 [2007-09-26 15:39 UTC] xenophex (Mark Statkus)
Hi, I've been having this problem and the above doesn't really tell me what I'm suppose to do to fix it?? I've tried it on PHP 4.4 and PHP 5 amd characterData is returning null on the root node value. Thanks, Mark