code: public static void transformDocumentToXml(DomDocument document, StreamResult result) {
      TransformerFactory transformerFactory = TransformerFactory.newInstance();
      try {
        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
  
        synchronized(document) {
          transformer.transform(document.getDomSource(), result);
        }
      } catch (TransformerConfigurationException e) {
        throw new ModelIoException("Unable to create a transformer for the model", e);
      } catch (TransformerException e) {
        throw new ModelIoException("Unable to transform model to xml", e);
      }
    }
docs: Transforms a {@link DomDocument} to XML output.
  
  @param document  the DOM document to transform
  @param result  the {@link StreamResult} to write to