PHP ate my XML's whitespace! I want it back!

Oh, how I love SimpleXML. Lovelovelove.
It's not powerful, but it put about 70% of the XML pie within
easy reach of my questing, clublike fingers. And it's got DOM...
interoperability, or something (probably not the right term) for when
I need to do more!

One thing I'm not so fond of is... PHP eats my whitespace. I
have a nice, human-readable list;

<hatlike_things>
<thing>
<hatlike>Canada</hatlike>
<headlike>Canada</headlike>
</thing>
<thing>
<hatlike>Thermosphere</hatlike>
<headlike>Mesosphere</headlike>
</thing>
<thing>
<hatlike>Kermit T. Frog</hatlike>
<headlike>Hand</headlike>
</thing>
</hatlike_things>

I load this list into an XML node, make some changes, and output it
back to XML again! Only now it usually looks thusly;

<hatlike_things><thing><hatlike>Canada</hatlike><headlike>Canada</
headlike></thing><thing><hatlike>Thermosphere</
hatlike><headlike>Mesosphere</headlike></thing><thing><hatlike>Kermit
T. Frog</hatlike><headlike>Hand</headlike></thing></hatlike_things>

The parser may not care, but I care! I want my whitespace back darn
it! I want to be able to read the results of a XML node I transform!
There was no joyful simple way of doing this when I last checked,
uh... 12-18 months ago. Has one emerged, in the interim?

(Many years ago, when I used macs extensively, i have a nifty
drag-and-drop program called 'the ugly stick' I could drop PC .txt
files on. It made them readable by fixing all the carriage-return
nonsense and turning a swarm of uneven line breaks into neat paragraph
blocks. This is what I seek- an Ugly Stick with which to beat
outputted XML into something I can use without a script mediating for
me.)

-Derik
ReGenesis0 [ Di, 08 April 2008 07:42 ] [ ID #1940501 ]

Re: PHP ate my XML's whitespace! I want it back!

..oO(Derik)

>I load this list into an XML node, make some changes, and output it
>back to XML again! Only now it usually looks thusly;
>
><hatlike_things><thing><hatlike>Canada</hatlike><headlike>Canada</
>headlike></thing><thing><hatlike>Thermosphere</
>hatlike><headlike>Mesosphere</headlike></thing><thing><hatlike>Kermit
>T. Frog</hatlike><headlike>Hand</headlike></thing></hatlike_things>
>
>The parser may not care, but I care! I want my whitespace back darn
>it! I want to be able to read the results of a XML node I transform!
>There was no joyful simple way of doing this when I last checked,
>uh... 12-18 months ago. Has one emerged, in the interim?

See the UCNs on
http://www.php.net/manual/en/function.simplexml-element-asXM L.php

In short: Use the DOM extension to get more control over the output
formatting.

Micha
Michael Fesser [ Di, 08 April 2008 15:49 ] [ ID #1940519 ]
PHP » comp.lang.php » PHP ate my XML's whitespace! I want it back!

Vorheriges Thema: Re: Strange 'Â' character output when using simplex
Nächstes Thema: Mysql database in UTF8, PHP shows latin1 (iso-8859-1)