public static String getDocumentAsString(Document document) {
Source source = new DOMSource(document);
StringWriter sw = new StringWriter();
Result streamResult = new StreamResult(sw);
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty(OutputKeys.INDENT, "no");
transformer.transform(source, streamResult);