|
Posted by Rik Wasmus on 01/12/08 02:19
On Sat, 12 Jan 2008 02:29:37 +0100, Jeremy <jeremy@pinacol.com> wrote:
> yawnmoth wrote:
>> <?php
>> $xml =3D new DOMDocument();
>> $xml->loadXML('
>> <a>
>> <b>test</b>
>> </a>
>> ');
>> $temp =3D $xml->createElement('b');
>> $temp->appendChild($xml->createTextNode('test'));
>> $xml->firstChild->appendChild($temp);
>> echo '<pre>';
>> echo htmlspecialchars($xml->saveXML());
>> echo '</pre>';
>> ?>
>> I'd like for this to be able to return this:
>> <a>
>> <b>test</b>
>> <b>test</b>
>> </a>
>> Instead, it produces this:
>> <a>
>> <b>test</b>
>> <b>test</b></a>
>> ie. the indentation convention that I'm using isn't being used by
>> saveXML(). Setting $xml->preserveWhiteSpace and $xml->formatOutput t=
o
>> true doesn't seem to help.
>> Any ideas as to what - if anything - I can do?
>
> You want preserveWhiteSpace =3D false and formatOutput =3D true (I kno=
w, =
> it's weird. But that's how it seems to work.) I think these options =
=
> also must be set directly after creating the new DOMDocument:
Settings formatOutput before loading indeed solved the problem, or, =
strangely anough, feeding it a string without ANY whitespace outside tag=
s =
(so '<a><b>test</b></a>').
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|