How to extract data from a SOAP response in Java?

眉间皱痕 提交于 2019-12-04 08:46:01

I started out trying to consume SOAP Web Services by hand like you describe - there are better ways.

There are libraries out there that will do all the work for you - no need to parse anything by hand.

Check out JAX-WS. Most Modern IDEs (Certainly Netbeans and Eclipse) also provide point and click support for building web service clients given a WSDL.

The biggest potential problem down this route is if there's no WSDL, or the WSDL is wrong, in which case the tooling I've linked might struggle.

The next safest thing would be to use an XML Parser like JAXP's SAX & DOM etc (they're right there in your JRE) to parse the response and then walk the data structures involved.

Finally you could go the string hacking route using splits or regexes but down that path lies a great deal of potential pain - there's more to the XML spec then nested tags.

It's strongly receommended that you not try and decode SOAP by hand :)

Just to expand on what @Brabster said, Netbeans has extensive Web Service support, especially using the JAX-WS library.

http://www.netbeans.org/kb/60/websvc/jax-ws.html#Exercise_3_1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!