Description
This behaves as expected:
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$root = $dom->createElement('root');
$dom->appendChild($root);
$root->appendChild($dom->createElement('child', 'nodevalue B'));
echo $dom->saveXml();
Output:
<root>
<child>nodevalue B</child>
</root>
But when a node contains both a child text node and a child element node the output is collapsed. The following code:
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$root = $dom->createElement('root', 'nodeValue A');
$dom->appendChild($root);
$root->appendChild($dom->createElement('child', 'nodevalue B'));
echo $dom->saveXml();
Resulted in this output:
<root>nodeValue A<child>nodevalue B</child></root
But I expected this output instead:
<root>nodeValue A
<child>nodevalue B</child>
</root>
PHP Version
PHP 8.3.12
Operating System
Ubuntu 24.04.01