So you are going to output an XML Document to a file using this canonical method. But how do you tell the Transformer object how the output should look like?
You use OutputKeys, that’s how.
For example:
transformer.setOutputProperty(OutputKeys.INDENT,"yes");