note 126934 added to class.domdocument
| From: | 610010559 at qq dot com | Date: | Thu, 17 Mar 2022 02:39:36 +0000 |
| Subject: | note 126934 added to class.domdocument | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-217733@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.135 (proxied: 112.5.202.222)
----
Manual Page -- https://php.net/manual/en/class.domdocument.php
Edit -- https://main.php.net/note/edit/126934
Del: integrated -- https://main.php.net/note/delete/126934/integrated
Del: useless -- https://main.php.net/note/delete/126934/useless
Del: bad code -- https://main.php.net/note/delete/126934/bad+code
Del: spam -- https://main.php.net/note/delete/126934/spam
Del: non-english -- https://main.php.net/note/delete/126934/non-english
Del: in docs -- https://main.php.net/note/delete/126934/in+docs
Del: other reasons-- https://main.php.net/note/delete/126934
Reject -- https://main.php.net/note/reject/126934
Search -- https://main.php.net/manage/user-notes.php