php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #46791 DOMDocumentFragment::appendXML should honor preserveWhiteSpace property
Submitted: 2008-12-07 12:35 UTC Modified: 2020-11-06 12:53 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: grodny at oneclick dot sk Assigned: cmb (profile)
Status: Closed Package: DOM XML related
PHP Version: 5.2.7 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: grodny at oneclick dot sk
New email:
PHP Version: OS:

 

 [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>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-04 00:38 UTC] 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
 [2011-01-23 21:24 UTC] jani@php.net
-Package: Feature/Change Request +Package: DOM XML related
 [2020-11-06 12:53 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2020-11-06 12:53 UTC] cmb@php.net
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();
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 06:01:32 2024 UTC