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 (((Root) obj).getEncoding() != null) {
transformer.setEncoding(((Root) obj).getEncoding());
}
if (((Root) obj).getXMLVersion() != null) {
transformer.setVersion(((Root) obj).getXMLVersion());
}
transformer.transform(n, result);
if(oldEncoding != null){
transformer.setEncoding(oldEncoding);
}
if(oldVersion != null){
transformer.setVersion(oldVersion);
}
} else {
transformer.transform(n, result);
}
}