Node n = this.marshaller.objectToXML(obj, node, desc, domRecord, isXMLRoot, this.getDocumentPreservationPolicy());
validateNode(n);
DOMResult result = new DOMResult(node);
XMLTransformer transformer = marshaller.getTransformer();
if (isXMLRoot) {
String oldEncoding = transformer.getEncoding();
String oldVersion = transformer.getVersion();
if (((XMLRoot) obj).getEncoding() != null) {
transformer.setEncoding(((XMLRoot) obj).getEncoding());
}
if (((XMLRoot) obj).getXMLVersion() != null) {
transformer.setVersion(((XMLRoot) obj).getXMLVersion());
}
transformer.transform(n, result);
if(oldEncoding != null){
transformer.setEncoding(oldEncoding);
}
if(oldVersion != null){
transformer.setVersion(oldVersion);
}
} else {
transformer.transform(n, result);
}
}