读书人

org.w3c.dom.DOMException:WRONG_DOC

发布时间: 2013-07-16 22:38:05 作者: rapoo

org.w3c.dom.DOMException:WRONG_DOCUMENT_ERR
org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it.

Document doc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.parse(new ByteArrayInputStream(out.toByteArray()));

SOAPBody body = msg.getSOAPBody();
Node port = body.getChildNodes().item(0);

port.appendChild(doc.getFirstChild().getFirstChild());

appendChild,添加节点的时候提示A node is used in a different document than the one that created it.

请问要怎么办?谢谢!

[解决办法]
另外一个Document不能像当前的Document 添加节点

Document respDoc = body.getOwnerDocument();
port.appendChild(respDoc.adoptNode(doc.getFirstChild()));

读书人网 >XML SOAP

热点推荐