How to force java xml dom to produce newline after <?xml version="1.0" encoding="UTF-8"?>?
Try this
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount","2");
Another solution is : transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,"yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "10");