<p>I'm using <code>org.w3c</code> <code>XML API</code> to open an existing <code>XML</code> file. I'm removing some nodes , and I'm adding others instead.</p>

<p>The problem is that the new nodes that are added are written one after the other, with no newline and no indentation what so ever. While it's true that the <code>XML</code> file is valid , it is very hard for a human to examine it.</p>

<p>Is there anyway to add indentation , or at least a newline after each node?</p>

I'm assuming that you're using a
```
Transformer
```
to do the actual writing (to a
```
StreamResult
```
). In which case, do this before you call
```
transform
```
:
```
```
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
```
```