Re: Files unformatted
Brought to you by:
bs_php,
nigelswinson
From: Nigel S. <nig...@us...> - 2002-07-23 23:38:43
|
> The fourth option is what i want! Import without skipping whitespaces and > export with skipping whitespaces. Then he keeps the linebreaks. But if i > open the file again and export it with skipped whitespaces again i get > something like this: > > <?xml version="1.0"?> > > <aaa> > > <bbb>This is > a text > with linebreaks!</bbb> > > </aaa> > > And one mor time it looks like this: > > <?xml version="1.0"?> > > > <aaa> > > > <bbb>This is > > a text > > with linebreaks!</bbb> > > > </aaa> > > And so on...so what is needed is an option that pretty prints the xml > structure without using the trim function on the content of the texts. This > fourth possibility seems to do that but if you use it several times on a > file it becmes unreadable again like i described above. > > The attached example should convince you that this is a bug. The example.php > only opens the file sets SkopWhitespace and outputs the file again. The > problem is that the pretty printed file becomes unreadable after a few > times. I see what you are trying to do now, but this doesn't convince me that it is a bug, it's a request for enhancement. The class is designed so that you are either skipping whitespace, or you are not. If you repeatedly import/export a file with this setting in either state, then the XML file will not "grow". If it did, then that would be a bug. If you parse in and keep whitespace, then write out in the other mode, then you are pushing the "skip whitespace" feature past what it was designed to support. I'm not sure why these line breaks are so important to you, but line breaks and whitespace in XML files is meant to have no meaning other than aesthetics, so we provide an option so that you either do your own formatting because your whitespace has meaning or you don't like the way we do it (skip white spaces off), or you let the class do the formatting for you (skip white spaces on). http://www.w3.org/TR/2000/REC-xml-20001006#sec-white-space So you want a mode where skipWhiteSpaces won't junk whitespace intrernally in the text data of an element? It will preserve all tabs, newlines, and spaces, and junk them only if the entire textual content is whitespace, and ltrim() and rtrim() all other entries? If there is a general desire for such a feature to be implemented then I might have a go, but as I have no need for it, I can't see me looking into this with any kind of priority. If you want to "play" with this feature yourself, then the function you want to modify is: function _handleCharacterData($parser, $text) { if ($this->parsInCData >0) $text = $this->_translateAmpersand($text, $reverse=TRUE); if ($this->bDebugXmlParse) echo "Handling character data: '".htmlspecialchars($text)."'<br>"; if ($this->parseSkipWhiteCache AND !empty($text) AND !$this->parsInCData) { HERE >>> // Special case CR. CR always comes in a separate data. Trans. it to '' or ' '. HERE >>> // If txtBuffer is already ending with a space use '' otherwise ' '. $bufferHasEndingSpace = (empty($this->parsedTextLocation) OR substr($this->parsedTextLocation, -1) === ' ') ? TRUE : FALSE; if ($text=="\n") { $text = $bufferHasEndingSpace ? '' : ' '; } else { if ($bufferHasEndingSpace) { $text = ltrim(preg_replace('/\s+/', ' ', $text)); } else { $text = preg_replace('/\s+/', ' ', $text); } } if ($this->bDebugXmlParse) echo "'Skip white space' is ON. reduced to : '" .htmlspecialchars($text) . "'<br>"; } $this->parsedTextLocation .= $text; } If you come up with something that works quite well then if you send the change in then we'll look into incorporating it into the main branch. Cheers, Nigel > ----- Original Message ----- > From: "Nigel Swinson" <nig...@us...> > To: "Jens Habermann" <Jen...@we...> > Cc: <php...@li...> > Sent: Tuesday, July 23, 2002 12:23 PM > Subject: Re: Files unformatted > > > > Ok I ran your script and see the same output, so I'm glad to say that this > > isn't a freak issue that won't "travel". :o) > > > > Using the SkipWhitespaces option, and the string you are inputing I can > get: > > > > import without export without > > > > <?xml version="1.0"?> > > <aaa><bbb>This is > > a text > > with linebreaks!</bbb></aaa> > > > > import with export without (Your example was missing this one...) > > > > <?xml version="1.0"?> > > <aaa><bbb>This is a text with linebreaks!</bbb></aaa> > > > > import with export with (This is the one you labelled "buggy") > > > > <?xml version="1.0"?> > > <aaa> > > <bbb>This is a text with linebreaks!</bbb> > > </aaa> > > > > import without export with > > > > <?xml version="1.0"?> > > <aaa> > > <bbb>This is > > a text > > with linebreaks!</bbb> > > </aaa> > > > > Which seems to be all four possible options. Will none of these do you? > If > > not then what do you want? :o/ > > > > Nigel > > > > =========================== > > For the most recent version of Php.XPath, and an archive of this list > visit: > > http://www.sourceforge.net/projects/phpxpath > > ----- Original Message ----- > > From: "Jens Habermann" <Jen...@we...> > > To: "Nigel Swinson" <nig...@us...> > > Sent: Monday, July 22, 2002 11:59 PM > > Subject: Re: Files unformatted > > > > > > > OK here it is :) > > > > > > Ive written a little example which outputs 3 different xml files. Inside > > the > > > example.php i described the problem. > > > > > > The output files as i get them are included too. Take a look at them > > before > > > starting the example.php to realise the difference between them. I think > > you > > > will get the same output as iam but maybe you wont believe me but your > > eyes > > > :) > > > > > > ----- Original Message ----- > > > From: "Nigel Swinson" <nig...@us...> > > > To: "Jens Habermann" <Jen...@we...> > > > Sent: Tuesday, July 23, 2002 12:13 AM > > > Subject: Re: Files unformatted > > > > > > > > > > > Ok here is an example: > > > > > > > > > > <aaa>This is > > > > > > > > > > a text > > > > > > > > > > that has line breaks > > > > > </aaa> > > > > > > > > > > if i toggle whitespace to TRUE the output is: <aaa>This is a text > that > > > has > > > > > line breaks</aaa> > > > > > > > > > > What ive found out so far is that the trim function of php also > > deletes > > > > > linebreaks ("\n") what seems to be the problem... > > > > > > > > > > So i have to choose if i want to have pretty printed text without > > > > linebreaks > > > > > or an unreadable chunk with linebreaks :) > > > > > > > > > > I have included another variable to the PHP.XPath class called > > > > > $prettyPrinted. At the moment im looking for all the places where > the > > > > class > > > > > formats the text and write some new lines which are checking for a > > true > > > > > $prettyPrinted variable and then do the same as skipWhitespace des > > > without > > > > > deleting my linebreaks :) > > > > > > > > Well good luck then :o) > > > > > > > > If you want me to help you, then I have to be able to reproduce the > > issue > > > > locally, which means me running EXACTLY the same .php and .xml input > and > > > > then comparing the generated output (html? xml?). I need more than > > just > > > an > > > > example of xml with a paragraph describing the operation. I need to > be > > > able > > > > to copy a couple of attachments to a folder, point my browser at the > php > > > > page, and then examine the results. :o) > > > > > > > > Sounds like you are happy sorting it out on your own :o). My only > > concern > > > > (for you) is that your changes aren't going to make it into the main > > > branch, > > > > which means you are gonna have to keep re-applying them.... > > > > > > > > Nigel > > > > > > > > > > |