« Reproduction of main problem with RPC | Main | Java 5, XPath and independent namespace declarations »
March 09, 2006
Converting SOAP to XML
At a first view there is no difficult to convert a SOAP message into an XML document (to be used as a org.w3c.dom.Document) as a SOAP message is an XML document. But how to tell this JAVA?
First approach:
org.w3c.dom.Document doc = (org.w3c.dom.Document)soapMessage;
This doesn't work (ClassCastException)
The only way I found is to do the following:
Use soapMessage.writeTo(Stream)
to write this to a Byte Array stream and then read the stream again with a DocumentBuilder to create a org.w3c.dom.Document.
Isn't there an easier way?
Posted by Dominik Marks at March 9, 2006 05:33 PM
Comments
Where does "soapMessage" come from? What API are you using? JAX-RPC?
In any case, "soapMessage.getClass().getName()" will tell you what class your object has, my guess is it's a javax.xml.SOAPEnvelope (http://java.sun.com/j2ee/1.4/docs/api/javax/xml/soap/SOAPEnvelope.html)
Posted by: Stefan Tilkov at March 9, 2006 06:35 PM
It is a javax.xml.soap.SOAPMessage.
I read the documentation, and as it does not implement org.w3c.dom.Document but java.lang.Object, so the class cast does not work.
Posted by: Dominik Marks at March 9, 2006 08:20 PM