Doc #77890 [ReO->Csd]: DOMDocument XML formatting (formatOutput) doesn't seem to work

From: Date: Mon, 26 Oct 2020 11:56:10 +0000
Subject: Doc #77890 [ReO->Csd]: DOMDocument XML formatting (formatOutput) doesn't seem to work
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-18031@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77890&edit=1

 ID:                 77890
 Updated by:         phpdocbot@php.net
 Reported by:        phpbugreport at mailinator dot com
 Summary:            DOMDocument XML formatting (formatOutput) doesn't
                     seem to work
-Status:             Re-Opened
+Status:             Closed
 Type:               Documentation Problem
 Package:            DOM XML related
 Operating System:   Windows
 PHP Version:        7.3.4
 Block user comment: N
 Private report:     N

 New Comment:

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


Previous Comments:
------------------------------------------------------------------------
[2019-04-15 19:33:49] requinix@php.net

Then don't close the report...

------------------------------------------------------------------------
[2019-04-15 19:31:35] phpbugreport at mailinator dot com

Thank you, luxian. This should be added to the documentation.

------------------------------------------------------------------------
[2019-04-15 08:17:26] 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-14 09:52:44] 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>


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=77890&edit=1


Thread (2 messages)

« previous php.doc.bugs (#18031) next »