PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » XML » XML_Tree » Bug #492

character data content at the end of root element is ignored

Details

Submitted2003-12-24 22:44 UTC
Fromchris_se at gmx dot net
Assigneddavey
StatusClosed
PackageXML_Tree
PHP VersionIrrelevant
OSAll
Roadmaps(Not assigned)

Comments

[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>