I'm using php DOM to build an XML file of data, it works fine but it all outputs on one line, like so:
<property><something><somethingelse>dfs</somethingelse></something></property>
However in all examples I've found it's outputting properly, like so:
<property>
<something>
<somethingelse>
dfs
</somethingelse>
</something>
</property>
Now I know I can force a new line with \n and \t for tab but I don't want to do this unless necessary. So, my question:
Is my server config (for some reason) forcing it to output on the same line,开发者_如何学运维 or is something else happening? All examples of this in use show no new line usage and they show new lines, so I think something is wrong.
I am declaring
header('Content-Type: text/xml');
Set the formatOutput attribute in your DOMDocument object to true
:
$domDocument->formatOutput = true;
By default, DOM won't add extra whitespace to your document. You can ask it to by setting
$doc->formatOutput = true;
See the corresponding entry in the manual.
It will not add whitespace to text nodes though, so the "dfs" in your example will not get indented this way.
精彩评论