|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-02-18 12:50 UTC] rrichards@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 19:00:02 2025 UTC |
Description: ------------ DomDocumentFragments witch replaced existing Nodes in a DomDocument is not globaly useable. * Create a DocumentFragment on an existing DomDocument. * Append one (or more) Child to this Fragment * Replace existing Node with this Fragment The Methods DomDocument->saveXML() displays the Document in the right way. When you use getElementsByTagName, XPath, or e.g. the XSL Extension these new Elements are not there. So in the Example the <replacement> will never be useable, only viewable. Reproduce code: --------------- <?php $xmlData = <<<XMLCONTENT <?xml version="1.0" encoding="utf-8"?> <test> <replace /> </test> XMLCONTENT; $dom = new DomDocument; $dom->loadXML( $xmlData ); $fragment = $dom->createDocumentFragment(); $replacement = $dom->createElement( 'replacement' ); $fragment->appendChild( $replacement ); $additionalNode = $dom->createElement( 'additionalNode' ); $fragment->appendChild( $additionalNode ); foreach( $dom->getElementsByTagName( 'replace' ) AS $node ) { $node->parentNode->replaceChild( $fragment, $node ); } echo "replacement tags found: " . $dom->getElementsByTagName( 'replacment' )->length . "\n\n"; echo "xml code used:\n"; echo $dom->saveXML(); ?> Expected result: ---------------- replacement tags found: 0 xml code used: <?xml version="1.0" encoding="utf-8"?> <test> <replacement/><additionalNode/> </test> Actual result: -------------- replacement tags found: 1 xml code used: <?xml version="1.0" encoding="utf-8"?> <test> <replacement/><additionalNode/> </test>