Req #46791 [Opn->Csd]: DOMDocumentFragment::appendXML should honor preserveWhiteSpace property

From: Date: Fri, 06 Nov 2020 12:53:13 +0000
Subject: Req #46791 [Opn->Csd]: DOMDocumentFragment::appendXML should honor preserveWhiteSpace property
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230162@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=46791&edit=1 ID: 46791 Updated by: cmb@php.net Reported by: grodny at oneclick dot sk Summary: DOMDocumentFragment::appendXML should honor preserveWhiteSpace property -Status: Open +Status: Closed Type: Feature/Change Request Package: DOM XML related PHP Version: 5.2.7 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: 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(); Previous Comments: ------------------------------------------------------------------------ [2009-08-04 00:38:07] david at stantonstreet dot com Agreed; I have encountered this behavior as well in HTML template parsing and am not getting the benefit of removing white-space from an appended content fragment, but the imported template has all whitespace removed. Thank you guys, David ------------------------------------------------------------------------ [2008-12-07 12:35:41] 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> ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=46791&edit=1

« previous php.bugs (#230162) next »