@@ -0,0 +1,1811 @@
+package com.thoughtworks.xstream.io.xml;%0A%0Aimport com.thoughtworks.xstream.core.util.FastStack;%0Aimport com.thoughtworks.xstream.io.HierarchicalStreamWriter;%0Aimport com.thoughtworks.xstream.io.StreamException;%0A%0Aimport org.dom4j.Branch;%0Aimport org.dom4j.Document;%0Aimport org.dom4j.DocumentFactory;%0Aimport org.dom4j.Element;%0Aimport org.dom4j.io.XMLWriter;%0A%0Aimport java.io.IOException;%0A%0Apublic class Dom4JWriter implements HierarchicalStreamWriter %7B%0A%0A    private final DocumentFactory documentFactory;%0A    private final FastStack elementStack = new FastStack(16);%0A    private final XMLWriter writer;%0A%0A    public Dom4JWriter(DocumentFactory documentFactory, XMLWriter writer) %7B%0A        this.documentFactory = documentFactory;%0A        this.writer = writer;%0A        elementStack.push(documentFactory.createDocument());%0A    %7D%0A%0A    public void startNode(String name) %7B%0A        Element element = documentFactory.createElement(name);%0A        top().add(element);%0A        elementStack.push(element);%0A    %7D%0A%0A    public void setValue(String text) %7B%0A        top().setText(text);%0A    %7D%0A%0A    public void addAttribute(String key, String value) %7B%0A        ((Element) top()).addAttribute(key, value);%0A    %7D%0A%0A    public void endNode() %7B%0A        elementStack.popSilently();%0A    %7D%0A%0A    private Branch top() %7B%0A        return (Branch) elementStack.peek();%0A    %7D%0A%0A    public void flush() %7B%0A        if (elementStack.size() == 1) %7B%0A            final Document document = (Document)elementStack.peek();%0A            try %7B%0A                writer.write(document);%0A                writer.flush();%0A            %7D catch (IOException e) %7B%0A                throw new StreamException(e);%0A            %7D%0A        %7D%0A    %7D%0A%0A    public void close() %7B%0A        flush();%0A    %7D%0A%0A    public HierarchicalStreamWriter underlyingWriter() %7B%0A        return this;%0A    %7D%0A%7D%0A

Create a branch from the old Dom4JWriter as Dom4JDomWriter.