Bug #77890 [Opn->Csd]: DOMDocument XML formatting (formatOutput) doesn't seem to work
| From: | phpbugreport at mailinator dot com | Date: | Mon, 15 Apr 2019 19:31:35 +0000 |
| Subject: | Bug #77890 [Opn->Csd]: DOMDocument XML formatting (formatOutput) doesn't seem to work | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-220471@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
User updated by: phpbugreport at mailinator dot com
Reported by: phpbugreport at mailinator dot com
Summary: DOMDocument XML formatting (formatOutput) doesn't
seem to work
-Status: Open
+Status: Closed
Type: Bug
Package: XML Writer
Operating System: Windows
PHP Version: 7.3.4
Block user comment: N
Private report: N
New Comment:
Thank you, luxian. This should be added to the documentation.
Previous Comments:
------------------------------------------------------------------------
[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