doc.write(writer);
OutputFormat format = new OutputFormat(); format.setNewlines(true); format.setIndent(true); XMLWriter xmlWriter = new XMLWriter(writer, format); xmlWriter.write(doc); xmlWriter.close();
    public static String asString(Document doc) {        try {            StringWriter writer = new StringWriter();            doc.write(writer);            return writer.toString();        } catch (IOException e) {            e.printStackTrace(System.err);            Assert.fail(e.getMessage());            return null;        }    }