Reply to Re: changing indentation with DOMDocument

Your name:

Reply:


Posted by Jeremy on 01/12/08 01:29

yawnmoth wrote:
> <?php
> $xml = new DOMDocument();
> $xml->loadXML('
> <a>
> <b>test</b>
> </a>
> ');
>
> $temp = $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 to
> true doesn't seem to help.
>
> Any ideas as to what - if anything - I can do?

You want preserveWhiteSpace = false and formatOutput = true (I know,
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:

$xml = new DOMDocument;
$xml->preserveWhiteSpace = false;
$xml->formatOutput = true;

// do whatever you do

echo $xml->saveXML(); //output is indented


Jeremy

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация