Friday, 17 June 2016

[Java] How to Indent XML Generated by Transformer

● Not Indent

1
<?xml version="1.0" encoding="UTF-8" standalone="no"?><a><b/></a>

● Indent

1
2
3
4
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<a>
 <b/>
</a>


◎ Java Code

1
2
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2")

No comments:

Post a Comment