File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes Can I use a SAXParser on a SOAPMessage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Can I use a SAXParser on a SOAPMessage" Watch "Can I use a SAXParser on a SOAPMessage" New topic

Can I use a SAXParser on a SOAPMessage

Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 276
Hi All,
I am new to SOAP so please forgive me if I mix apples and oranges here.
I have a java web app that uses soap and I need to parse a SoapMessage object. I would like to use the parse method of a SAXParser object to do this.
I have found a tutorial on using a SAXParser by extending an org.xml.sax.helpers.DefaultHandler class, but the example expects a user to parse a file, not a SOAPMessage. The parse method seems to expect a path to a file, and I am having trouble finding resources on making this work for a SOAPMessage. A lot of sites recommend using Axis, but I must work with SOAP as this is how another app I communicate with is set up.
Could anyone point me at a good resource that I could use that will help me to parse a javax.xml.soap.SOAPMessage object using SAX ?
Paul Clapham

Joined: Oct 14, 2005
Posts: 19864

Well, there's the API documentation for a start. If you look at it, you will see that there are several overloaded versions of parse that allow you to parse not only from a File, but also (for example) from an InputStream.

But looking at the API documentation for SOAPMessage, I see that you can get a SOAPBody object from it, and a SOAPHeader object, and so on. The documentation for those two objects says that they implement org.w3c.Element. In other words, the parsing is already done for you if you get those objects. You can just use ordinary DOM-wrangling techniques to access the data.
Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 276
Thank you, that makes sense, maybe I am making this harder than it has to be. I will take a look at that.
Don't get me started about those stupid light bulbs.
subject: Can I use a SAXParser on a SOAPMessage
It's not a secret anymore!