Java Reference
In-Depth Information
catalog'>12345</i:isbn>";
//Create a SOAP request based on our XML string
StreamSource request = new StreamSource(new StringReader(payload));
out.println("\nInvoking...");
//Send the request and get the response
Source bookResponse = dispatch.invoke(request);
//Now we have to transform our result source object
//into a DOM tree to work with it
DOMResult dom = new DOMResult();
Transformer trans =
TransformerFactory.newInstance().newTransformer();
trans.transform(bookResponse, dom);
//Extract values with XPath
XPathFactory xpf = XPathFactory.newInstance();
XPath xp = xpf.newXPath();
NodeList resultNodes = (NodeList) xp.evaluate("//title",
dom.getNode(), XPathConstants.NODESET);
//Show the result
String title = resultNodes.item(0).getTextContent();
out.println("TITLE=" + title);
} catch (MalformedURLException mue) {
mue.printStackTrace();
} catch (WebServiceException wsex) {
wsex.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
}
The value of the response SOAP envelope contained in the Source looks like this:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header/>
<S:Body>
<ns2:book xmlns:ns2="http://ns.soacookbook.com/catalog">
<isbn>12345</isbn>
<author><firstName>William</firstName><lastName>Shakespeare</lastName>
</author>
<title>King Lear</title>
Search WWH ::




Custom Search