note 76867 added to function.dom-domdocument-savexml

From: Date: Fri, 03 Aug 2007 00:10:41 +0000
Subject: note 76867 added to function.dom-domdocument-savexml
Groups: php.notes 
Request: Send a blank email to php-notes+get-129138@lists.php.net to get a copy of this message
Comment to `devin at SPAMISBAD dot tritarget dot com''s post: Thanks for pointing out the pitfalls of formatOutput' vs. load*()'. This has certainly saved me from some possible surprises. I think the seemingly strange behaviour can be explained. Warning: The following stuff is mostly based on deductions and experiments. Much less on studying the sources and specs (I'm not sure some of these would provide answer anyway, at least not easily). As you point out, preserveWhiteSpace' must be set before loading the DOM from the source string (I'm working with loadXML()' but I believe the situation should be the same with load()' you used). This looks logical, as this property seems to control the parsing and DOM creation process during which text nodes containing the whitespace are either included or dropped. This can be proven by dumping the DOM structure and comparing the results based on the value of preserveWhiteSpace'. With preserveWhiteSpace' set to FALSE', no text nodes containing whitespace will be present in the returned DOM. When this property is `TRUE', these nodes will be present. Note: When speaking about the whitespace in the previous paragraph, we're most certainly speaking about so called whitespace in element content' or element content whitespace', if I'm not mistaken. See also my comment in the notes of `DOMText->isWhitespaceInElementContent()' method. As for the mysterious effect on the output of saveXLM()', I think the explanation lies in the presence or absence of the above mentioned whitespace text nodes. This was also proven by experiments: After adding such a node into a DOM which contained none (the DOM was created using loadXML()' with preserveWhiteSpace' set to FALSE'), the output formatting got affected in a such a way, the formatting got lost for the rest of the document after the added node. I think the presence of whitespace text nodes forces such rendering, that the content of these nodes is used to separate adjoining nodes thus disabling default formatting. Only when there are no such text nodes present, the ouput formatting takes effect (provided the formatOutput' is set to TRUE', of course). Well, the thing I don't really understand is how you did get an output of a signle line with formatOutput' set to TRUE'. This has happened to me when no whitespace text nodes were present (ie. when loading the XML with preserveWhiteSpace' set to FALSE') *and* with formatOutput' set to *FALSE'* (with the opposite value of `formatOutput', the formatting should do it's work and you should not end up with just one line). But I haven't seen your source. Perhaps you had whitespace nodes containing no new-lines in your DOM? As for the CAUTION about root element, I didn't see any problems with empty root element neither in shortened nor full form. What did you have in mind, when you said it WORKS' or DOES NOT WORK'? ---- Server IP: 147.32.160.17 Probable Submitter: 147.229.9.14 ---- Manual Page -- http://www.php.net/manual/en/function.dom-domdocument-savexml.php Edit -- https://master.php.net/note/edit/76867 Del: integrated -- https://master.php.net/note/delete/76867/integrated Del: useless -- https://master.php.net/note/delete/76867/useless Del: bad code -- https://master.php.net/note/delete/76867/bad+code Del: spam -- https://master.php.net/note/delete/76867/spam Del: non-english -- https://master.php.net/note/delete/76867/non-english Del: in docs -- https://master.php.net/note/delete/76867/in+docs Del: other reasons-- https://master.php.net/note/delete/76867 Reject -- https://master.php.net/note/reject/76867 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129138) next »