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 #1238

Parsing files strips all new line characters

Details

Submitted2004-04-19 09:25 UTC
Frommborowka at clever-age dot com
Assigneddavey
StatusClosed
PackageXML_Tree
PHP Version4.3.4
OSLinux
Roadmaps(Not assigned)

Comments

[2004-04-19 09:25 UTC] mborowka at clever-age dot com

Description:
------------
I am using the XMLTree to parse some files with big, mutliline, CDATA sections. Unfortunately, XML_Tree strips all the new line characters. I checked the code and to my big surprise, the function cdataHandler trims all the data before storing them:
if (trim($data)) {
$this->cdata .= $data;
}

This makes no sense to me. CDATA sections should be parsed as-is and no modification should be performed...

Reproduce code:
---------------
$xmlTree = new XML_Tree();
$content = "<?xml version='1.0'?>
<ala atrr='aaa'><beta><![CDATA[Line one
Ligne Two]]></beta></ala>";
$xmlTree->getTreeFromString($content);
$xmlTree->dump();

Expected result:
----------------
<?xml version="1.0"?>
<ala atrr="aaa">
<beta>Line one
Ligne Two</beta>
</ala>

Actual result:
--------------
<?xml version="1.0"?>
<ala atrr="aaa">
<beta>Line oneLigne Two</beta>
</ala>

[2004-05-18 08:06 UTC] mborowka at clever-age dot com

The problem is not with the "trim" but with the "if" itself.
Think about a situation where you have only a \r in the string... if is false and your \r is not added to the resulting cdata.