Merge two different Dom

如果有两个dom结构的document,想要直接将B document append到A document里面会提示错误:
org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it.
正确的方法是:
private Document buildACK(List resynDocList) throws ParserConfigurationException {
if (!this.successDoc && this.sucess()) {
return null;
}

Document ackDoc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().newDocument();
Element response = ackDoc.createElement(“Response”);
ackDoc.appendChild(response);
// modify to set real resyn documents start
/*Element requestID = ackDoc.createElement(“RequestID”);
if (uuid != null) {
requestID.setTextContent(uuid.toString());
}
response.appendChild(requestID);*/

for(Document resynDoc : resynDocList){
Element resynElement = resynDoc.getDocumentElement();
Node importedResynNode = ackDoc.importNode(resynElement, true);
response.appendChild(importedResynNode);
}
// modify to set real resyn documents end

Element responseCodeEle = ackDoc.createElement(“ResponseCode”);
responseCodeEle.setTextContent(Integer.toString(responseCode));
response.appendChild(responseCodeEle);

Element message = ackDoc.createElement(“Message”);

if (responseMsg == null) {
message.setTextContent(“Command has been executed succesfully.”);
} else {
message.setTextContent(responseMsg);
}

response.appendChild(message);
return ackDoc;
}
正确的方法,使用import将B document导入到A document的结构中