@Override
protected void marshalDomNode(Object graph, Node node) throws XmlMappingException {
HierarchicalStreamWriter streamWriter;
if (node instanceof Document) {
streamWriter = new DomWriter((Document) node);
}
else if (node instanceof Element) {
streamWriter = new DomWriter((Element) node, node.getOwnerDocument(), new XmlFriendlyReplacer());
}
else {
throw new IllegalArgumentException("DOMResult contains neither Document nor Element");
}
marshal(graph, streamWriter);