This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
I am trying to parse inputxml using parser.
Bellow is code
When I am calling parseXML(InputXML)
it is throwing error is follows
please suggest me how to resolve;-(
input xml is---><root><Value1>first</Value1><Value2>second</Value2></root>
parsing is completed
Error thrown in parser class
java.lang.ClassCastException: com.sun.org.apache.xerces.internal.dom.DeferredElementImpl cannot be cast to org.w3c.dom.Document at WLST.test1.parseXML(test1.java:33)
1. The parse method of DocumentBuilder returns a Document instance. So you don't need to do a cast on it when you store it into a Document type variable. So the external cast here can be removed.
2. getDocumentElement() method in the Document class returns an Element. So again you don't need to cast it. Why do you cast the variable doc to type Document? It's already of the type Document.
3. The error should be thrown in this line of code where you try to cast an Element to a Document. It's an incompatible cast and hence you receive the ClassCastException at runtime. Why do you want to cast it anyways?
The basic thing you should learn is about "Java type casting". You should get lot of useful links if you search the internet.