Reputation: 663
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
Upvotes: 1
Views: 4670
Reputation: 8511
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...
Upvotes: 3