File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes XML Parser issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML Parser issue" Watch "XML Parser issue" New topic
Author

XML Parser issue

Shanmugam Muthukumarasamy
Ranch Hand

Joined: Jan 11, 2003
Posts: 83
Hi All,
Actually I am getting the following exception while using org.apache.xerces.dom.DocumentImpl.adoptNode(),
this method is not able to understand by the application running on WSAD / WebSphere 4.0
The Exception is:
2bc8b7 ExceptionUtil X CNTR0020E: Non-application exception occurred while processing method respondToRq on bean BeanId(BP#BPEJB.jar#FdpsXMLRqMgr, null): java.lang.NoSuchMethodError: org.apache.xerces.dom.DocumentImpl: method adoptNode(Lorg/w3c/dom/Node V not found
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
com.ibm.ejs.container.UncheckedException: ; nested exception is:
java.lang.NoSuchMethodError: org.apache.xerces.dom.DocumentImpl: method adoptNode(Lorg/w3c/dom/Node V not found
com.ibm.ejs.container.UncheckedException: ; nested exception is:
java.lang.NoSuchMethodError: org.apache.xerces.dom.DocumentImpl: method adoptNode(Lorg/w3c/dom/Node V not found
java.lang.NoSuchMethodError: org.apache.xerces.dom.DocumentImpl: method adoptNode(Lorg/w3c/dom/Node V not found
[Friday, November 22, 2002 5:35:33 PM EST]
If anyone have the solution, please let me know as soon as possible.
Thanks,
Shanmugam.
shanmugam.muthukumarasamy@prudential.com
shankumaran@yahoo.com


SJCP 1.4<br />SCWCD 1.4<br />SCEA
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi Shanmugam,
You have probably compiled your code using a different version of Xerces than the one installed in your application server.
Cheers
Shanmugam Muthukumarasamy
Ranch Hand

Joined: Jan 11, 2003
Posts: 83
Hi Beno�t d'Oncieu

Thanks for your immediate reply. Actually this applcation is running fine in VAJ environment with the IBMParser.jar. This Jar file is having the org.apache.xerces.dom.DocumentImpl class.
But now I am trying to migrate this application to WSAD. In WSAD, runtime library, this is having different jar file (Xerces.jar). This Jar file is also having same package Structure. So what I did is I removed the Xerces.jar from the Runtime library and added IBMParser.jar and I tried. For that case also it is failing at adoptNode() method. And I tried to include the Xerces.jar which is coming along with WSAD in the runtime library and application library. Still I am getting the same problem. I don't know why it is ..? I am really confused and I don't know how to proceed with.
Please have a look on the the following code and if you have any suggestion please tell me.

org.apache.xerces.dom.DocumentImpl xmlDoc=(org.apache.xerces.dom.DocumentImpl)this.iO_OriginalXMLDoc;
xmlDoc.adoptNode((Node)vO_newElement);
//xmlDoc.appendChild((Node)vO_newElement);
//Node tmpNode = xmlDoc.importNode((Node)vO_newElement,true);
Node tmpNode=this.iO_CurrentNode.insertBefore(vO_newElement,vO_refElement);
if (vb_MoveToChild) {
this.iO_CurrentNode = tmpNode;
}

The Exception is:
ExceptionUtil X CNTR0020E: Non-application exception occurred while processing method respondToRq on bean BeanId(BP#BPEJB.jar#FdpsXMLRqMgr, null): java.lang.NoSuchMethodError: org.apache.xerces.dom.DocumentImpl: method adoptNode(Lorg/w3c/dom/Node V not found
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
com.ibm.ejs.container.UncheckedException: ; nested exception is:
java.lang.NoSuchMethodError: org.apache.xerces.dom.DocumentImpl: method adoptNode(Lorg/w3c/dom/Node V not found
com.ibm.ejs.container.UncheckedException: ; nested exception is:
java.lang.NoSuchMethodError: org.apache.xerces.dom.DocumentImpl: method adoptNode(Lorg/w3c/dom/Node V not found
java.lang.NoSuchMethodError: org.apache.xerces.dom.DocumentImpl: method adoptNode(Lorg/w3c/dom/Node V not found
The place it is getting failed in the above code is:
xmlDoc.apoptNode(Node)
Thanks,
Shanmugam.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
You should be able to get away with it by using the importNode() method instead of the adoptNode() as importNode() is a public method of the org.w3c.dom.Document interface it does not use any implementation class. This should work with any Xercers version.
Try to avoid using internals (implementation classes) as often as you can, to avoid these kind of problems. Your code will be more portable accross implementation vendors and versions.
Using only standard APIs like DOM, SAX, JAXP and TraX (eventually JDOM), you should be able to do every kind if XML manipulation without having to resort to using internal API. Only do this in last resort or for performance reasons (and add relevant javadoc when you do this) or when you want to experiment.
Best regards
Shanmugam Muthukumarasamy
Ranch Hand

Joined: Jan 11, 2003
Posts: 83
Hi Beno�t d'Oncieu,
Thank you very much for your reply. As per your suggestion, I got out of that Exception made by adoptNode() method. Now my application working fine with importNode() method. But still it is failing at insertBefore() method. Can you tell me what is the purpose of boolean parameter in the importNode() method. When we have to send "true" and when we have to send "false".
The code :
org.apache.xerces.dom.DocumentImpl xmlDoc=(org.apache.xerces.dom.DocumentImpl)this.iO_OriginalXMLDoc;
//xmlDoc.adoptNode((Node)vO_newElement);
//xmlDoc.appendChild((Node)vO_newElement);
/*Node tmpNode = */xmlDoc.importNode((Node)vO_newElement,true);
Node tmpNode=this.iO_CurrentNode.insertBefore(vO_newElement,vO_refElement);
if (vb_MoveToChild) {
this.iO_CurrentNode = tmpNode;
}
Exception:
org.w3c.dom.DOMException: DOM005 Wrong document
org.w3c.dom.DOMException: DOM005 Wrong document
do you have any idea..?
Once again thanks for your help.
regards,
Shanmugam.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
You would have found it by yourself by looking at the javadocs
Anyway, assuming that you are being a firewall that only let you access the javaranch web site, I'll give you some help
The importNode method takes two parameters. The first one is the node to import, the second one should be set to true when you want a deep copy (all descendant nodes as well). In extremely rare situations, you could want to only copy the node without any children, and that's when to use false.
This method returns a new node that has your document as owner. You can then integrate the node in your document.
So, for your code to work, you will have to use this return value (I have simplified your code as well):

Cheers
Shanmugam Muthukumarasamy
Ranch Hand

Joined: Jan 11, 2003
Posts: 83
Hi Beno�t d'Oncieu,
Thank you very much for your help.
regards,
Shanmugam.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML Parser issue