|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2002-06-04 10:37 UTC] jtate@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 20:00:01 2025 UTC |
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"; } } ?>