Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What are you trying to accomplish?</p> <p>By setting <code>preserveWhiteSpace</code> to <code>true</code> (unnecessary; that's the default), you are telling libxml not to ignore text nodes that are composed only of white space. Yet, at the same time, you're trying to pretty format the XML file, which to be really pretty requires whitespace nodes.</p> <p>Then, even ignoring white space, you have to realize the whitespace inside the <code>&lt;seg&gt;</code> tags is significant; libxml will not remove those; if you force a line break after <code>text 1</code>, in the next line the <code>&lt;/seg&gt;</code> closing tag must not be indented, otherwise the content of the text node inside the tag would differ.</p> <p>Your code gives me this:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;body&gt; &lt;seg&gt; text 1 &lt;/seg&gt; &lt;seg&gt; text 2 &lt;/seg&gt;&lt;/body&gt; </code></pre> <p>Since you're telling libxml that whitespace is significant, it cannot put a line break after the second <code>&lt;/seg&gt;</code>, otherwise it'd be creating another text node.</p> <p>If you say <code>$dom-&gt;preserveWhiteSpace = false;</code>:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;body&gt; &lt;seg&gt; text 1 &lt;/seg&gt; &lt;seg&gt; text 2 &lt;/seg&gt; &lt;/body&gt; </code></pre> <p>The tags are indented, but libxml still cannot do this:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;body&gt; &lt;seg&gt; text 1 &lt;/seg&gt; &lt;seg&gt; text 2 &lt;/seg&gt; &lt;/body&gt; </code></pre> <p>because it would be changing the content of the text nodes inside <code>&lt;seg&gt;</code>.</p> <p>You might want to try <a href="http://pt.php.net/tidy" rel="nofollow noreferrer">tidy</a>, though I'm not sure it'll do what you want.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload