note 102279 added to libxml.constants
@oneseventeen
| Newsgroups | php.notes |
|---|---|
| Message-ID | <[email protected]> |
When inserting XML DOM Elements inside existing XML DOM Elements that I loaded from an XML file using the following code, none of my new elements were formatted correctly, they just showed up on one line:
<?php
$dom = DOMDocument::load('file.xml');
$dom->formatOutput = true;
//$dom->add some new elements with child nodes somewhere inside the loaded XML using insertBefore();
$dom->saveXML();
//output: everything looks normal but the new nodes are all on one line.
?>
I found I could pass LIBXML_NOBLANKS to the load method and it would reformat the whole document, including my added stuff:
<?php
$dom = DOMDocument::load('file.xml', LIBXML_NOBLANKS);
$dom->formatOutput = true;
//$dom->add some new elements with child nodes somewhere inside the loaded XML using insertBefore();
$dom->saveXML();
//output: everything looks newly formatted, including new nodes
?>
Hope this helps, took me hours of trial and error to figure this out!
----
Server IP: 69.147.83.197
Probable Submitter: 69.92.83.131
----
Manual Page -- http://www.php.net/manual/en/libxml.constants.php
Edit -- https://master.php.net/note/edit/102279
Del: integrated -- https://master.php.net/note/delete/102279/integrated
Del: useless -- https://master.php.net/note/delete/102279/useless
Del: bad code -- https://master.php.net/note/delete/102279/bad+code
Del: spam -- https://master.php.net/note/delete/102279/spam
Del: non-english -- https://master.php.net/note/delete/102279/non-english
Del: in docs -- https://master.php.net/note/delete/102279/in+docs
Del: other reasons-- https://master.php.net/note/delete/102279
Reject -- https://master.php.net/note/reject/102279
Search -- https://master.php.net/manage/user-notes.php