tags:

views:

35

answers:

1

Hi, currently making a SOAP request using Java's SOAPConnectionFactory and SOAPConnection's .call() method, which returns a SOAPMessage object, and I would like to apply an XPath query to it. Is this at all possible, or am I going about it completely wrong?

As far as I can work out, I'd have to somehow convert SOAPMessage to an InputSource which I can then apply the XPath to, but I can't quite work out how to go about doing this.

Thanks, Peter

+1  A: 

SOAPBody can be cast to Node. So, you can use it like this:

URL endpoint = new URL("http://www.webservicex.net/whois.asmx");
SOAPMessage message = connection.call(sm, endpoint);
XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(new SoapNamespaceContext());
Node resultNode = (Node) xpath.evaluate("//m:GetWhoISResult", message.getSOAPBody(), XPathConstants.NODE);
... do something with resultNode...
Georgy Bolyuba
Thanks - this is almost identical to what I did in the end :-)
welp