Page 1 of 1

How to preserve newlines when formatting XML

Posted: Thu Jan 05, 2006 2:27 pm
by huijzer
Hi,

When I format my XML files, empty lines are removed. Is there a way to prevent this form happening. The empty lines are there for readability :-)

Before:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<test>
<node><a/></node>

<node><b/></node>
</test>
After:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<test>
<node>
<a/>
</node>
<node>
<b/>
</node>
</test>
What I would like:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<test>
<node>
<a/>
</node>

<node>
<b/>
</node>
</test>
Is this possible?

Thanks in advance for any help!

Arjan Huijzer

Posted: Thu Jan 05, 2006 4:57 pm
by george
Hi,

You can achieve that if you set the spaces to be preserved for the test element and to be stripped for the node element. You can set the preserve/strip spaces state for a node either using the xml:space attribute with the preserve and default as values or by adding the element name to the preserve or strip spaces element lists from Options->Preferences -- Editor / Format dialog.

Best Regards,
George