public static String toString(Document doc, String indent)
throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputFormat format = OutputFormat.createPrettyPrint();
format.setIndent(indent);
format.setLineSeparator("\n");
XMLWriter writer = new XMLWriter(baos, format);
writer.write(doc);