php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41931 domdocument->savexml does not have formatoutput effect
Submitted: 2007-07-09 03:07 UTC Modified: 2007-07-09 16:13 UTC
From: c00lways at gmail dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.2.3 OS: windows xp prof
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: c00lways at gmail dot com
New email:
PHP Version: OS:

 

 [2007-07-09 03:07 UTC] c00lways at gmail dot com
Description:
------------
when:
domdocument->preserveWhiteSpace = false;
domdocument->formatoutput( true );
...
domdocument->savexml( domelement );

does not have formatoutput effect on savexml( domelement )

the output string is only 1 line...



Reproduce code:
---------------
$dom = new DomDocument("1.0", "iso-8859-1");
        
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;

$domme = $dom->createElement( "xx" );



$domme->appendChild(new DOMElement("subxx"));

//try to force, but still same output
$domme->preserveWhiteSpace = false;
$domme->formatOutput = true;

$dom->appendChild( $domme );

        
return $dom->saveXML( $domme );


Expected result:
----------------
<xx>
  <subxx />
</xx>

Actual result:
--------------
<xx><subxx /></xx>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-09 11:52 UTC] rrichards@php.net
You are probably looking at the results through a browser (or using a different script that is buggy) as the script (once you change the return to echo) outputs the correct results as expected.
 [2007-07-09 13:24 UTC] c00lways at gmail dot com
No,
still not working:

example code:

$dom = new DomDocument();
        
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
        
$xdom = $dom->createElement( "yyy", "yyyy value" );

$xdom->preserveWhiteSpace = false;
$xdom->formatOutput = true;
        
$xchild = $dom->createElement( "OOO", "ooo value" );
        
$xdom->appendChild( $xchild );
        
$dom->appendChild( $xdom );
        
echo $dom->saveXML( $xdom );
 [2007-07-09 13:25 UTC] c00lways at gmail dot com
No,
still not working
 [2007-07-09 14:11 UTC] rrichards@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

and now you are using mixed content (yyy contains both textual and element nodes as children) so don't expect any formatting within there ... still bogus  
 [2007-07-09 14:34 UTC] c00lways at gmail dot com
is this still bogus?

it's weird, even without parameter in it, i still get 
non-formated output

$dom = new DomDocument();
        
        $dom->preserveWhiteSpace = true;
        $dom->formatOutput = false;
        
        $xdom = $dom->createElement( "yyy" );
        
        $xchild = $dom->createElement( "OOO" );
        
        $xchild2 = $dom->createElement( "subchild2" );
        $xchild3 = $dom->createElement( "subchild3", "sub3" );
        
        $xchild4 = $dom->createElement( "subchild4", "sub4" );
        
        $xchild5 = $dom->createElement( "subchild5" );
        
        $xchild2->setAttribute( "width", 200 );
        
        $xchild2->appendChild( $xchild3 );
        $xchild2->appendChild( $xchild4 );
        $xchild2->appendChild( $xchild5 );
        
        $xchild->appendChild( $xchild2 );
        
        
        $xdom->appendChild( $xchild );
        
        $dom->appendChild( $xdom );
        
        echo $dom->saveXML( );
 [2007-07-09 14:41 UTC] rrichards@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

bogus (code is wrong). please do not re-open 
 [2007-07-09 15:16 UTC] c00lways at gmail dot com
HOW CAN YOU SAY IT'S WRONG?

http://www.w3schools.com/dom/dom_validate.asp
indicate my output from the code is valid xml..

 you guys are funny!
 [2007-07-09 16:13 UTC] c00lways at gmail dot com
Sorry,
i 've forgotten to turn it back on for formatoutput.

my bad...
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 07 10:01:34 2025 UTC