Bug #17560 Updated: dump_mem with format mangles doc for subsequent requests
| From: | jtate@php.net | Date: | Tue, 04 Jun 2002 14:37:10 +0000 |
| Subject: | Bug #17560 Updated: dump_mem with format mangles doc for subsequent requests | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-9472@lists.php.net to get a copy of this message | ||
ID: 17560
Updated by: jtate@php.net
Reported By: jhpellerin@attbi.com
-Status: Open
+Status: Closed
Bug Type: DOM XML related
Operating System: Linux (redhat 7.2) + Apache 1.3.
PHP Version: 4.2.1
New Comment:
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a
documentation
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.
Applied patch by Rob Richards.
Previous Comments:
------------------------------------------------------------------------
[2002-06-02 00:29:21] jhpellerin@attbi.com
Calling $doc->dump_mem or $doc->dump_file with format set to true seems
to corrupt the internal representation of the XML document, removing
all writespace-only text nodes, which alters the structure of the
document. It doesn't affect the document object in the same request,
but all subsequent requests that access an identical XML doc -- even on
a different page -- will see the altered structure instead of the
structure actually present in the original doc.
Workaround: set format to false
Config: './configure' '--with-apxs=/opt/apache/bin/apxs' '--with-dom'
'-with-dom-xslt' '--with-dom-exslt' '--prefix=/opt'
'--with-zlib'
Demo script:
<?php
$xml = "<?xml version=\"1.0\"?>
<motel>
<roaches>
<roach state=\"alive\"/>
<roach state=\"dead\"/>
<roach state=\"dead\"/>
</roaches>
</motel>";
$doc = domxml_open_mem($xml);
echo "First listing:<br>\n";
list_roaches($doc);
/*
Calling dump mem with format set to true
alters the in-memory copy the xml file, even
across reloads of the page!
With the whitespace stripped, the structure
of the document changes.
*/
$foo = $doc->dump_mem(true);
echo "After doc->dump_mem called:<br>\n";
list_roaches($doc);
echo "Now, reload to see error<br>\n";
function list_roaches ($doc)
{
$root = $doc->document_element();
$first_child = $root->first_child();
$roaches_el = $first_child->next_sibling();
if ($roaches_el) {
$roaches_list = $roaches_el->get_elements_by_tagname("roach");
for ($i = 0; $i < count($roaches_list); $i++) {
echo " Roach $i is " . $roaches_list[$i]->get_attribute("state")
. "<br>\n";
}
} else {
echo "No sibling of first child found!<br><xmp>\n";
echo $doc->dump_mem();
echo "</xmp>\n";
}
}
?>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=17560&edit=1