If I use saveHTML() without the optional DOMnode parameter it works as expected:
$html = '<html><body><div>123</div><div>456</div></body></html>';
$dom = new DOMDocument;
$dom->preserveWhiteSpace = true;
$dom->formatOutput = false;
$dom->loadHTML($html, LIBXML_HTML_NODEFDTD);
echo $dom->saveHTML();
<html><body><div>123</div><div>456</div></body></html>
But when I add a DOMNode parameter to output a subset of the document it seems to ignore the formatOutput property and adds a bunch of unwanted whitespace:
$body = $dom->getElementsByTagName('body')->item(0);
echo $dom->saveHTML($body);
<body> <div>123</div> <div>456</div> </body>
What gives? Is this a bug? Is there a workaround?