|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 15 11:00:01 2025 UTC |
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'); ?>