ConFoo Montreal 2026: Call for Papers

Voting

: max(five, six)?
(Example: nine)

The Note You're Voting On

610010559 at qq dot com
3 years ago
when you add the new element to formatted XML data through appendChild() method, you would the new element you add is not be formatted(that is not indexed, not line break). here is my solution (in short load the xml without preserve white space, ), example show as below:
<?php
$doc
= new \DOMDocument();
$doc->formatOutput = true;
$doc->preserveWhiteSpace = false;//that is key, default value is true.
$doc->loadXML($xmlStr);
$doc->appendChild($doc->createElement('php', '666'))
$formattedXMLStr = $doc->saveXML();//DOMDocument wold format the xml str for you
echo $formattedXMlStr;
?>
it take me some time to try it out. hope it save your time.

<< Back to user notes page

To Top