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

From: Date: Mon, 15 Apr 2019 19:33:49 +0000
Subject: Bug->Doc #77890 [Csd->ReO]: DOMDocument XML formatting (formatOutput) doesn't seem to work
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-16578@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:         requinix@php.net
 Reported by:        phpbugreport at mailinator dot com
 Summary:            DOMDocument XML formatting (formatOutput) doesn't
                     seem to work
-Status:             Closed
+Status:             Re-Opened
-Type:               Bug
+Type:               Documentation Problem
-Package:            XML Writer
+Package:            DOM XML related
 Operating System:   Windows
 PHP Version:        7.3.4
 Block user comment: N
 Private report:     N

 New Comment:

Then don't close the report...


Previous Comments:
------------------------------------------------------------------------
[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 (#16578) next »