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

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

am 08.04.2008 07:42:28 von ReGenesis0

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;



Canada
Canada


Thermosphere
Mesosphere


Kermit T. Frog
Hand



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

CanadaCanada headlike>Thermosphere hatlike>MesosphereKermit
T. Frog
Hand


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

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

am 08.04.2008 15:49:11 von Michael Fesser

..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;
>
>CanadaCanada >headlike>Thermosphere >hatlike>MesosphereKermit
>T. Frog
Hand

>
>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