code: public static String documentToString(Document xmlDocument) throws IOException {
          String encoding = (xmlDocument.getXmlEncoding() == null) ? "UTF-8" : xmlDocument.getXmlEncoding();
          OutputFormat format = new OutputFormat(xmlDocument);
          format.setLineWidth(65);
          format.setIndenting(true);
          format.setIndent(2);
          format.setEncoding(encoding);
          try (Writer out = new StringWriter()) {
              XMLSerializer serializer = new XMLSerializer(out, format);
              serializer.serialize(xmlDocument);
              return out.toString();
          }
      }
docs: Returns a String representation for the XML Document.
  
  @param xmlDocument the XML Document
  @return String representation for the XML Document
  @throws IOException