Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prettifying Java XML output

Tags:

java

xml

I have a simple question about Java's XML API and I hope there's a simple answer too:

Lets say that after processing I have the following XML output:

<a>
    <b><c>
    <d> <e> some content
        </e>    </d>
    </c>    </b>
</a>

The structure is correct but whitespaces are all over the place. The question is that how can I prettify the output so that it looks something like this:

<a>
    <b>
        <c> 
            <d>
                <e>some content</e>
            </d>
        </c>
    </b>
</a>

Only catch is that I can't use anything but Java 5's own XML API.

like image 330
Esko Avatar asked Oct 15 '22 17:10

Esko


1 Answers

Use Transformer.setOutputProperty(OutputKeys.INDENT, "yes").

like image 141
Bombe Avatar answered Oct 18 '22 15:10

Bombe