|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-01-20 12:54 UTC] rrichards@php.net
[2005-01-20 22:51 UTC] brian dot sanders at cometsystems dot com
[2005-01-21 01:42 UTC] rrichards@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 07:00:01 2025 UTC |
Description: ------------ We have encountered the following bug when using libxml2 (via PHP5): When we set the value of a text node, ampersands (&) are not being converted to XML entities. These raw characters truncate our text node, resulting in lost data. For example, after setting nodeValues, less-than's (<) show up as entities (<) in our XML file. However, ampersands (&) show up as raw characters (&). Note that in the example code we have silenced the output from setting the nodeValues, as this generates a PHP warning when used with newer versions of libxml2. We have experienced this bug on at least two machines, with the following configurations: MACHINE 1: LIBXML2: 2.6.16-3 (binary rpm) PHP: 5.0.2 (built from source) OS: Fedora Core Linux 3 KERNEL: 2.6.9-1.681_FC3smp MACHINE 2: LIBXML2: 2.6.7-28.4 (binary) PHP: 5.0.2 (built from source) OS: Suse Linux 9.1 KERNEL: 2.6.4-52-default Reproduce code: --------------- <?php /* load the document */ $dom = DomDocument::loadXML(<<<XML <?xml version="1.0"?> <test> <foo>Here is an < to test.</foo> <bar>Here is an & to test.</bar> </test> XML ); /* confirm we have the document verbatim */ print("HERE IS THE INITIAL DOCUMENT:\n\n"); print($dom->saveXML()); print("\n--------------------------------\n\n"); /* get the LT node */ $nodeList = $dom->getElementsByTagName('foo'); $nodeLT = $nodeList->item(0); /* get the AMP node */ $nodeList = $dom->getElementsByTagName('bar'); $nodeAMP = $nodeList->item(0); /* resave the node values */ @$nodeLT->nodeValue = $nodeLT->nodeValue; @$nodeAMP->nodeValue = $nodeAMP->nodeValue; /* show the altered document */ print("HERE IS THE DOCUMENT AFTER THE SAVE:\n\n"); print($dom->saveXML()); print("\n--------------------------------\n\n"); ?> Expected result: ---------------- HERE IS THE INITIAL DOCUMENT: <?xml version="1.0"?> <test> <foo>Here is an < to test.</foo> <bar>Here is an & to test.</bar> </test> -------------------------------- HERE IS THE DOCUMENT AFTER THE SAVE: <?xml version="1.0"?> <test> <foo>Here is an < to test.</foo> <bar>Here is an & to test.</bar> </test> Actual result: -------------- HERE IS THE INITIAL DOCUMENT: <?xml version="1.0"?> <test> <foo>Here is an < to test.</foo> <bar>Here is an & to test.</bar> </test> -------------------------------- HERE IS THE DOCUMENT AFTER THE SAVE: <?xml version="1.0"?> <test> <foo>Here is an < to test.</foo> <bar>Here is an </bar> </test>