I'm currently writing xml to xml doc in java but it's not properly formatted, its formatted like this :
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
Instead of like this, what can I do to align it properly as the rest of the document?
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
I've got a response about possible duplicate, that may be the case but in my case its not working here is my code :
private void writeFile(File file) {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
StreamResult resultStream = new StreamResult(new StringWriter());
DOMSource source = new DOMSource(getDocument());
transformer.transform(source, resultStream);
BufferedWriter out = new BufferedWriter(new FileWriter(file));
out.write(resultStream.getWriter().toString().trim());
out.close();
}