code: private static void write(
          Node node, Writer writer, int indentation, boolean omitXmlDeclaration)
      {
          TransformerFactory transformerFactory = 
              TransformerFactory.newInstance();
          if (indentation > 0)
          {
              transformerFactory.setAttribute("indent-number", indentation);
          }
          Transformer transformer = null;
          try
          {
              transformer = transformerFactory.newTransformer();
          }
          catch (TransformerConfigurationException canNotHappen)
          {
              // Can not happen here
              throw new XmlException(
                  "Could not create transformer", canNotHappen);
          } 
          transformer.setOutputProperty(OutputKeys.STANDALONE, "yes");
          transformer.setOutputProperty(
              OutputKeys.INDENT, 
              propertyStringFor(indentation > 0));
          transformer.setOutputProperty(
              OutputKeys.OMIT_XML_DECLARATION, 
              propertyStringFor(omitXmlDeclaration));
          DOMSource source = new DOMSource(node);
  
          StreamResult xmlOutput = new StreamResult(writer);
          try
          {
              transformer.transform(source, xmlOutput);
          }
          catch (TransformerException e)
          {
              throw new XmlException("Could not transform node", e);
          }
      }
docs: Writes a formatted String representation of the given XML node
  to the given writer.
  
  @param node The node
  @param writer The writer to write to
  @param indentation The indentation. If this is not positive, then
  no indentation will be performed
  @param omitXmlDeclaration Whether the XML declaration should be omitted
  @throws XmlException If there was an error while writing