Re: Files unformatted
Brought to you by:
bs_php,
nigelswinson
From: Sam B. <bs...@us...> - 2002-07-24 22:20:48
|
Hi Nigel, Hi Jens, I've been following the correspondence of you 2 and somehow have the feeling that Jens is not trying to do something special. He's just doing it in the wrong sequence and is unaware of the it (as I will show below). And Nigel is assuming that Jens wants to do it in that sequence and is unaware that Jens just made a mistake. So what do I mean: It has to do with the option "skip white spaces" and beautifying the XML output. First you must know that when "skip white spaces" is set to TRUE, PHP.XPath always beautified the exported XML because we can safely assume that adding spaces and line brakes to the output will not change the XML content (otherwise PHP.XPath would not be allowed to skip them in the first place). Some time in Php.XPath V2.x I introduced this "skip white spaces" feature and set it the default to TRUE. Now in V3.x it default is set to FALSE.. (Mainly because it was using up to much CPU). Now you can turn it on again BUT you must do it before you IMPORT the XML; it's late to turn it on before you export and will cause the funny output Jens toled about. Here is a sample code that will show you that V3 works as V2 and also shows the effect Jens has when setting "skip white spaces" to late. Hope this will solve the "missunderstanding" ---------------------------------------------------------------------------- <? include('../XPath.class.php'); $head = '<?xml version="1.0"?>'; $xml_input=<<<EOD $head <aaa> <bbb>This is a text with linebreaks!</bbb> </aaa> EOD; echo '<hr>This is the XML given:<hr><pre>'; echo htmlspecialchars($xml_input); echo '</pre>'; # ============================================================================ $xPath =& new XPath; // In V3 skip white spaces has to be turned on (used to be on by default) $xPath->setSkipWhiteSpaces(TRUE); $xPath->importFromString($xml_input); echo '<hr>This is the XML after import with "skip white spaces" set to <strong>ON</strong>:<hr><pre>'; echo $xPath->exportAsHtml(); echo '</pre>'; # ============================================================================ $xPath->reset(); $xPath->setSkipWhiteSpaces(FALSE); $xPath->importFromString($xml_input); echo '<hr>This is the XML after import with "skip white spaces" set to <strong>OFF</strong>:<hr><pre>'; echo $xPath->exportAsHtml(); echo '</pre>'; # ============================================================================ $xPath->reset(); $xPath->importFromString($xml_input); $xPath->setSkipWhiteSpaces(TRUE); echo '<hr>This is what happens if you turn on "skip white spaces" to late !! (After import):<hr><pre>'; echo $xPath->exportAsHtml(); echo '</pre>'; ?> ---------------------------------------------------------------------------- -- Sam Blum <bs...@us...> =========================== For the most recent version of PHP.XPath and an archive of this list visit: http://sourceforge.net/projects/phpxpath |