Note that there are some explanatory texts on larger screens.

plurals
  1. POJava read in SOAP mesage using xpath
    text
    copied!<p>I have the following soap message:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"&gt;&lt;soap:Header&gt;&lt;wsse:Security env:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;wsse:UsernameToken xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"&gt;&lt;wsse:Username&gt;test&lt;/wsse:Username&gt;&lt;wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"&gt;11111111&lt;/wsse:Password&gt;&lt;/wsse:UsernameToken&gt;&lt;/wsse:Security&gt;&lt;/soap:Header&gt; &lt;soap:Body xmlns:ns1="http://www.acme.co.za"&gt; &lt;ns1:pingMeCallback&gt; &lt;ns1:message&gt;abc&lt;/ns1:message&gt; &lt;/ns1:pingMeCallback&gt; &lt;/soap:Body&gt; &lt;/soap:Envelope&gt; </code></pre> <p>I need to use xpath to read in the message value. My code is as follows:</p> <pre><code> DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource data = new InputSource(in); Node doc = builder.parse("ping.xml"); // set up a document purely to hold the namespace mappings DOMImplementation impl = builder.getDOMImplementation(); Document namespaceHolder = impl.createDocument("http://www.acme.co.za/","f:namespaceMapping", null); Element root = namespaceHolder.getDocumentElement(); root.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:SOAP","http://schemas.xmlsoap.org/soap/envelope/"); root.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:ns1","http://schemas.xmlsoap.org/soap/envelope/"); NodeList results = XPathAPI.selectNodeList(doc,"/SOAP:Envelope/SOAP:Body/ns1:pingMeCallback/ns1:message",root); for (int i = 0; i &lt; results.getLength(); i++) { Node result = results.item(i); XObject value = XPathAPI.eval(result, "string()"); System.out.println(value.str()); } </code></pre> <p>My code prints out nothing. Can anybody find out what I am doing wroing?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload