code: public static OutputStream marshal(Document document, OutputStream out, String encoding) throws CmsXmlException {
  
          try {
              OutputFormat format = OutputFormat.createPrettyPrint();
              format.setEncoding(encoding);
  
              XMLWriter writer = new XMLWriter(out, format);
              writer.setEscapeText(false);
  
              writer.write(document);
              writer.close();
  
          } catch (Exception e) {
              throw new CmsXmlException(Messages.get().container(Messages.ERR_MARSHALLING_XML_DOC_0), e);
          }
  
          return out;
      }
docs: Marshals (writes) an XML document into an output stream using XML pretty-print formatting.<p>
  
  @param document the XML document to marshal
  @param out the output stream to write to
  @param encoding the encoding to use
  @return the output stream with the xml content
  @throws CmsXmlException if something goes wrong