code: @Override
      public void marshalWriter(Object graph, Writer writer, DataHolder dataHolder) throws XmlMappingException,
              IOException {
          if (graph instanceof Document) {
              OutputFormat outputFormat = OutputFormat.createCompactFormat();
              outputFormat.setSuppressDeclaration(suppressXmlDeclaration);
  
              XMLWriter xmlWriter = new XMLWriter(writer, outputFormat);
              try {
                  xmlWriter.write((Document)graph);
              } finally {
                  try {
                      xmlWriter.flush();
                  } catch (Exception ex) {
                      logger.debug("Could not flush XMLWriter", ex);
                  }
              }
          } else {
              if (!suppressXmlDeclaration) {
                  writer.write(XML_DECLARATION);
              }
  
              HierarchicalStreamWriter streamWriter = new EscapingCompactWriter(writer);
              try {
                  getXStream().marshal(graph, streamWriter, dataHolder);
              } catch (Exception ex) {
                  throw convertXStreamException(ex, true);
              } finally {
                  try {
                      streamWriter.flush();
                  } catch (Exception ex) {
                      logger.debug("Could not flush HierarchicalStreamWriter", ex);
                  }
              }
          }
      }
docs: Just as super(), but instead of a {@link com.thoughtworks.xstream.io.xml.CompactWriter} creates a {@link
  EscapingCompactWriter}.
  Also if the object graph is a Dom4j document, the document is written directly instead of using XStream.