PHP XMLWriter,如何插入换行符? [英] PHP XMLWriter, how to insert a line break?
问题描述
我正在使用 XMLWriter http://www.php.net/manual/en/book.xmlwriter.php 让我的网络客户端创建一个 XML 文件.一开始必须有一个元素有很多属性,像这样:
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');
所以 XML 文件中的那部分看起来像这样:
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.
我宁愿这样:
<registry-request att1="long text" att2="long text"
att3="long text" att4="long text">
我在 XMLWriter php.net 文档中没有找到解决方案,有人知道如何做到这一点吗?只需添加典型的换行命令,例如:
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');
没有帮助.
谢谢.
推荐答案
实际上 $xml->setIndent(1);
就是这样做的.令人惊讶!
Actually the $xml->setIndent(1);
does exactly that. Surprisingly!
这篇关于PHP XMLWriter,如何插入换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!