PHP XMLWriter, how to insert a line break?

此生再无相见时 提交于 2019-12-14 01:20:07

问题


I'm using XMLWriter http://www.php.net/manual/en/book.xmlwriter.php to let my webclient create an XML File. In the beginning there has to be an element with very many attributes, like this:

$xml->startElement('registry-request');
$xml->writeAttribute('att1', 'long text');
$xml->writeAttribute('att2', 'long text');
$xml->writeAttribute('att3', 'long text');
$xml->writeAttribute('att4', 'long text');

So that part in the XML file will look something like this:

<registry-request att1="long text" att2="long text" att3="long text" att4="long text">

Which with real input looks quite terrible.

I would much rather have it like this:

<registry-request att1="long text" att2="long text" 
att3="long text" att4="long text">

I didn't find a solution in the XMLWriter php.net documentation, anyone got an idea how to do this? Just adding typical linebreak commands like:

$xml->writeAttribute('att2', 'long text\n');

doesn't help.

Thanks.


回答1:


Actually the $xml->setIndent(1); does exactly that. Surprisingly!



来源:https://stackoverflow.com/questions/10207455/php-xmlwriter-how-to-insert-a-line-break

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!