|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-12-07 12:35 UTC] grodny at oneclick dot sk
Description:
------------
Description:
------------
Appending XML source to fragment and then inserting fragment to document tree should result in consitent white space handling, based on document's preserveWhiteSpace property value.
Is it possible to make DOMDocumentFragment::appendXML method honor fragment's ownerDocument->preserveWhiteSpace property value?
Thank you.
Reproduce code:
---------------
$doc = new DOMDocument();
$doc->preserveWhiteSpace = false;
$doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
<root>
<child/>
</root>
');
$frag = $doc->createDocumentFragment();
$frag->appendXML('
<fragment>
<child/>
</fragment>
');
$doc->documentElement->appendChild($frag);
$doc->formatOutput = false;
echo $doc->saveXML();
Expected result:
----------------
<?xml version="1.0" encoding="utf-8"?>
<root><child/><fragment><child/></fragment></root>
Actual result:
--------------
<?xml version="1.0" encoding="utf-8"?>
<root><child/>
<fragment>
<child/>
</fragment>
</root>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 09:00:01 2025 UTC |
preserveWhitespace=false corresponds to passing the LIBXML_NOBLANKS option to any of the document *loading* functions. Other than that, it is not supported by libxml2, so there is nothing we can do. You can work around that by loading the document again, e.g. replace the last line of the given test script with $xml = $doc->saveXML(); $doc = new DOMDocument; $doc->preserveWhiteSpace = false; $doc->loadXML($xml); echo $doc->saveXML();