From: jon at mysql dot com Operating system: Windows2000 PHP version: 5.0.2 PHP Bug Type: DOM XML related Bug description: incomplete deep copy with importNode()
Description: ------------ When importing a DOM node from one document into another using DOMDocument->importNode(), the optional second argument with a value of TRUE should produce a deep copy of the imported node; that is, all child nodes of the imported node should be duplicated. (Similar to the effects of using the optional second argument with cloneNode().) Instead, only the first child of the imported node is included with the copy. Notes: 1. This problem is related to the new DOM extension, and not to the old DOMXML extension. 2. The same problem occurs regardless how the DOMDocument is instantiated: using LoadHTML(), LoadXML(), LoadHTMLFile(), or LoadXMLFile() to do so all produce the same (incorrect) result. 3. Per http://www.w3.org/TR/DOM-Level-2-Core/core.html#Core-Document-importNode -- "... deep of type boolean ... If true, recursively import the subtree under the specified node..."; the specific problem here is that the copy is not done recursively. Reproduce code: --------------- <?php $old_doc = DOMDocument::LoadXML("<html><head><title>OLD DOCUMENT</title></head><body><p>First paragraph.</p><p>Second paragraph.</p></body></html>"); $new_doc = DOMDocument::LoadXML("<html><head><title>NEW DOCUMENT</title></head><body></body></html>"); $old_body = $old_doc->getElementsByTagName("body")->item(0); $new_body = $new_doc->getElementsByTagName("body")->item(0); $div = $new_doc->createElement("div"); $div->setAttribute("class", "page"); $new_content = $new_doc->importNode($old_body, TRUE); foreach($new_content->childNodes as $child) $div->appendChild($child); $new_body->appendChild($div); print "<pre>" . htmlentities( $new_doc->saveXML() ) . "</pre>"; ?> Expected result: ---------------- <?xml version="1.0"?> <html><head><title>NEW DOCUMENT</title></head><body><div class="page"><p>First paragraph.</p><p>Second paragraph.</p></div></body></html> Actual result: -------------- <?xml version="1.0"?> <html><head><title>NEW DOCUMENT</title></head><body><div class="page"><p>First paragraph.</p></div></body></html> -- Edit bug report at http://bugs.php.net/?id=31089&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31089&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=31089&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=31089&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=31089&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=31089&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=31089&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=31089&r=needscript Try newer version: http://bugs.php.net/fix.php?id=31089&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=31089&r=support Expected behavior: http://bugs.php.net/fix.php?id=31089&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=31089&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=31089&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=31089&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31089&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=31089&r=dst IIS Stability: http://bugs.php.net/fix.php?id=31089&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=31089&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=31089&r=float MySQL Configuration Error: http://bugs.php.net/fix.php?id=31089&r=mysqlcfg