note 64319 added to function.dom-domdocument-loadxml

From: Date: Wed, 12 Apr 2006 09:28:44 +0000
Subject: note 64319 added to function.dom-domdocument-loadxml
Groups: php.notes 
Request: Send a blank email to php-notes+get-107846@lists.php.net to get a copy of this message
Note that loadXML crops off beginning and trailing whitespace and linebreaks. When using loadXML and appendChild to add a chunk of XML to an existing document, you may want to force a linebreak between the end of the XML chunk and the next line (usually a close tag) in the output file: $childDocument = new DOMDocument; $childDocument>preserveWhiteSpace = true; $childDocument->loadXML(..XML-Chunk..); $mNewNode = $mainDOcument->importNode($childDocument->documentElement, true); $ParentNode->appendChild($mNewNode); $ParentNode->appendChild($mainDocument->createTextNode("\\n "); Although it is said that DOM should not be used to make 'pretty' XML output, it is something I struggled with to get something that was readable for testing. Another solution is to use the createDocumentFragment()->appendXML(..XML-Chunk..) instead, which seems not to trim off linebreaks like DOMDocument->loadXML() does. ---- Server IP: 216.194.113.175 Probable Submitter: 67.172.167.104 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.dom-domdocument-loadxml.php Edit -- http://master.php.net/note/edit/64319 Del: integrated -- http://master.php.net/note/delete/64319/integrated Del: useless -- http://master.php.net/note/delete/64319/useless Del: bad code -- http://master.php.net/note/delete/64319/bad+code Del: spam -- http://master.php.net/note/delete/64319/spam Del: non-english -- http://master.php.net/note/delete/64319/non-english Del: in docs -- http://master.php.net/note/delete/64319/in+docs Del: other reasons-- http://master.php.net/note/delete/64319 Reject -- http://master.php.net/note/reject/64319 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#107846) next »