InputSource is = new InputSource(new StringReader(unformattedXml));
Document doc = db.parse(is);
DOMImplementationRegistry domReg = DOMImplementationRegistry.newInstance();
DOMImplementationLS lsImpl = (DOMImplementationLS) domReg.getDOMImplementation("LS");
LSSerializer lsSerializer = lsImpl.createLSSerializer();
lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
LSOutput output = lsImpl.createLSOutput();
output.setEncoding("UTF-8");
StringWriter destination = new StringWriter();