php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #77890 DOMDocument XML formatting (formatOutput) doesn't seem to work
Submitted: 2019-04-14 09:52 UTC Modified: 2020-10-26 11:58 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: phpbugreport at mailinator dot com Assigned: cmb (profile)
Status: Closed Package: DOM XML related
PHP Version: 7.3.4 OS: Windows
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: phpbugreport at mailinator dot com
New email:
PHP Version: OS:

 

 [2019-04-14 09:52 UTC] phpbugreport at mailinator dot com
Description:
------------
Hi,
the formatOutput property of DOMDocument class doesn't seem to work.
Tested PHP builds:
PHP 7.3.2 (cli) (built: Feb  5 2019 23:14:21) ( NTS MSVC15 (Visual C++ 2017) x86)
PHP 7.3.4 (cli) (built: Apr  2 2019 22:13:15) ( NTS MSVC15 (Visual C++ 2017) x86)


Test script:
---------------
File to process (in.xml):
<?xml version="1.0" encoding="iso-8859-1"?>
<root>
<a>
<b>
<c/>
</b>
</a>
</root>

<?php 
$dom = new DOMDocument;
$dom->load('in.xml');

$dom->formatOutput = true;
$dom->save("out.xml");
exit();
?>

Expected result:
----------------
I expect something like this:
<?xml version="1.0" encoding="iso-8859-1"?>
<root>
    <a>
        <b>
            <c />
        </b>
    </a>
</root>

Actual result:
--------------
The output is the same as the input
<?xml version="1.0" encoding="iso-8859-1"?>
<root>
<a>
<b>
<c/>
</b>
</a>
</root>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-04-15 08:17 UTC] luxian dot m at gmail dot com
In the comments section of DOMDocument there are people saying that you need to set 'preserveWhitespaces' to 'false' and 'formatOutput' before you load the file

This works:

<?php
$dom = new DOMDocument;
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->load('in.xml');
?>
 [2019-04-15 19:31 UTC] phpbugreport at mailinator dot com
-Status: Open +Status: Closed
 [2019-04-15 19:31 UTC] phpbugreport at mailinator dot com
Thank you, luxian. This should be added to the documentation.
 [2019-04-15 19:33 UTC] requinix@php.net
-Status: Closed +Status: Re-Opened -Type: Bug +Type: Documentation Problem -Package: XML Writer +Package: DOM XML related
 [2019-04-15 19:33 UTC] requinix@php.net
Then don't close the report...
 [2020-10-26 11:56 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=dd0cbeacdb03e799f05d24ef554ffa9d8394cc38
Log: Fix #77890: DOMDocument XML formatting (formatOutput) doesn't seem to work
 [2020-10-26 11:56 UTC] phpdocbot@php.net
-Status: Re-Opened +Status: Closed
 [2020-10-26 11:58 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2020-10-26 21:40 UTC] phpdocbot@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=34ac9df28cb6cebf9f125d8aedcac58c90e1d0a9
Log: Fix #77890: DOMDocument XML formatting (formatOutput) doesn't seem to work
 [2020-12-30 11:58 UTC] nikic@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=55cbabe5c86942e6e9bf19cf8be3c571eeb58430
Log: Fix #77890: DOMDocument XML formatting (formatOutput) doesn't seem to work
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 02:01:28 2024 UTC