2010-07-06 57 views
26

的一個,當我嘗試生成應該像org.w3c.dom.DOMException中:WRONG_DOCUMENT_ERR:一個節點在不同的文檔而不是創建它

<hold/> 
一個元素,我得到一個錯誤使用

使用由Axis2生成的java客戶端代碼。 Java代碼

HoldPayment hold = new HoldPayment() 
cr.setHold(hold); 

,但是當我火它關閉,我得到WRONG_DOCUMENT_ERR的錯誤。如果我不在消息中包含這個元素,它就可以正常工作。任何人有任何想法如何解決它?

AxisFault 
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException 
faultSubcode: 
faultString: org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it. 
faultActor: 
faultNode: 
faultDetail: 
     {http://xml.apache.org/axis/}stackTrace:org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it. 
     at com.sun.org.apache.xerces.internal.dom.ParentNode.internalInsertBefore(ParentNode.java:352) 
     at com.sun.org.apache.xerces.internal.dom.ParentNode.insertBefore(ParentNode.java:284) 
     at com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild(NodeImpl.java:235) 
     at org.apache.axis.message.SOAPFaultBuilder.onEndChild(SOAPFaultBuilder.java:305) 
     at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1090) 
     at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601) 
     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1774) 
     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2930) 
     at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648) 
     at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140) 
     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510) 
     at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807) 
     at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737) 
     at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107) 
     at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205) 
     at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522) 
     at javax.xml.parsers.SAXParser.parse(SAXParser.java:395) 
     at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227) 
     at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696) 
     at org.apache.axis.Message.getSOAPEnvelope(Message.java:435) 
     at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:796) 
     at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144) 
     at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32) 
     at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118) 
     at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83) 
     at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165) 
     at org.apache.axis.client.Call.invokeEngine(Call.java:2784) 
     at org.apache.axis.client.Call.invoke(Call.java:2767) 
     at org.apache.axis.client.Call.invoke(Call.java:2443) 
     at org.apache.axis.client.Call.invoke(Call.java:2366) 
     at org.apache.axis.client.Call.invoke(Call.java:1812) 
     at au.com.virginblue.www.schema._2005._02.booking_wsdl.BookingBindingStub.createReservation(BookingBindingStub.java:1803) 
     at com.test.GetDJBooking.main(GetDJBooking.java:215) 

     {http://xml.apache.org/axis/}hostname:test.com.au 

org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it. 
     at org.apache.axis.AxisFault.makeFault(AxisFault.java:101) 
     at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:701) 
     at org.apache.axis.Message.getSOAPEnvelope(Message.java:435) 
     at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:796) 
     at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144) 
     at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32) 
     at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118) 
     at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83) 
     at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165) 
     at org.apache.axis.client.Call.invokeEngine(Call.java:2784) 
     at org.apache.axis.client.Call.invoke(Call.java:2767) 
     at org.apache.axis.client.Call.invoke(Call.java:2443) 
     at org.apache.axis.client.Call.invoke(Call.java:2366) 
     at org.apache.axis.client.Call.invoke(Call.java:1812) 
     at au.com.virginblue.www.schema._2005._02.booking_wsdl.BookingBindingStub.createReservation(BookingBindingStub.java:1803) 
     at com.nhh.dj.GetDJBooking.main(GetDJBooking.java:215) 
Caused by: org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it. 
     at com.sun.org.apache.xerces.internal.dom.ParentNode.internalInsertBefore(ParentNode.java:352) 
     at com.sun.org.apache.xerces.internal.dom.ParentNode.insertBefore(ParentNode.java:284) 
     at com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild(NodeImpl.java:235) 
     at org.apache.axis.message.SOAPFaultBuilder.onEndChild(SOAPFaultBuilder.java:305) 
     at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1090) 
     at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601) 
     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1774) 
     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2930) 
     at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648) 
     at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140) 
     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510) 
     at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807) 
     at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737) 
     at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107) 
     at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205) 
     at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522) 
     at javax.xml.parsers.SAXParser.parse(SAXParser.java:395) 
     at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227) 
     at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696) 
     ... 14 more 

回答

2

您無法從一個文檔複製節點並將其粘貼到另一個文檔。試圖這樣做會導致這種類型的錯誤。

節點必須正確導入。如果我還記得,那麼Doc​​ument類爲這個常見任務提供了正確的方法。

編輯

問題可能是在setHold方法後面的代碼。該元素必須是,導入的是。如果這是全部自動生成的代碼,那麼尋找更新版本的軸可以解決問題。看到我的評論,我提到了一個軸1.3/1.4的問題。

+0

對不起,我不確定你的意思,我看不到從哪裏複製粘貼節點從一個文件到另一個文件。 我使用從Axis2 wsdl2java生成的客戶端代碼。它生成了一個添加元素的方法,但是當我添加它時會導致錯誤? – yurl 2010-07-06 07:52:26

+0

什麼是您的軸版本?至少有報道的問題在這裏:https://issues.apache.org/jira/browse/AXIS-2705 – 2010-07-06 08:12:27

+0

我使用1.4。我會看看使用1.5將會修復它。 – yurl 2010-07-07 01:06:31

67

我使用此實現將節點從一個XML文檔添加到其他節點。

Node firstDocImportedNode = firstDoc.importNode(secondDocsNode, true); 
firstDocNode.appendChild(firstDocImportedNode); 

看看是否有幫助。招數只是將節點導入其他文檔,而不是直接附加。

+0

如果firstDoc是您要從中獲取節點的文檔,而secondDoc是您將要使用它的文檔,那麼您應該使用:secondDoc.importNode(firstDocsNode,true),儘管「import」這個詞暗示了這一點。 – 2013-10-11 15:01:55

+0

像魅力一樣工作 – 2015-05-22 13:56:56

+0

任何想法什麼布爾(在這種情況下'true')代表? – dokaspar 2017-05-21 20:31:52

0

我們在用CXF發送SOAP消息時看到了這個錯誤。

org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it. 
at org.apache.xerces.dom.ParentNode.internalInsertBefore(ParentNode.java:351) 
at org.apache.xerces.dom.ParentNode.insertBefore(ParentNode.java:283) 
at org.apache.xerces.dom.CoreDocumentImpl.insertBefore(CoreDocumentImpl.java:393) 
at org.apache.xerces.dom.NodeImpl.appendChild(NodeImpl.java:236) 
at org.jboss.ws.core.soap.SOAPDocument.appendChild(SOAPDocument.java:226) 
at org.jboss.ws.core.soap.SOAPPartImpl.appendChild(SOAPPartImpl.java:300) 
at org.apache.cxf.staxutils.W3CDOMStreamWriter.setChild(W3CDOMStreamWriter.java:119) [cxf-common-utilities-2.5.4.jar:2.5.4] 
at org.apache.cxf.staxutils.W3CDOMStreamWriter.newChild(W3CDOMStreamWriter.java:109) [cxf-common-utilities-2.5.4.jar:2.5.4] 
at org.apache.cxf.staxutils.W3CDOMStreamWriter.writeStartElement(W3CDOMStreamWriter.java:137) [cxf-common-utilities-2.5.4.jar:2.5.4] 
at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.writeSoapEnvelopeStart(SoapOutInterceptor.java:122) [cxf-rt-bindings-soap-2.4.6.jar:2.4.6] 

錯誤發生在SoapOutInterceptor之前處理的SAAJOutInterceptor中。 Saaj實現來自JBoss。並且它用另一個類加載器創建文檔。 Saaj的這個文檔打破了SoapOutInterceptor。

我們解決了這個問題,增加了對我們模塊的依賴。

<dependency> 
    <groupId>com.sun.xml.messaging.saaj</groupId> 
    <artifactId>saaj-impl</artifactId> 
    <version>1.3</version> 
</dependency> 
相關問題