java - Retrieving Xpath from SOAP Message -



java - Retrieving Xpath from SOAP Message -

i want retrieve xpaths soap message @ run time.

for example, if have soap message like

<soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:bodyxmlns:ns1="http://xmlns.oracle.com/testappln_jws/testemail/testemail"> <ns1:process> <ns1:to></ns1:to> <ns1:subject></ns1:subject> <ns1:body></ns1:body> </ns1:process> </soap:body> </soap:envelope>

then possible xpaths soap message are

/soap:envelope/soap:body/ns1:process/ns1:to /soap:envelope/soap:body/ns1:process/ns1:subject /soap:envelope/soap:body/ns1:process/ns1:body

how can retrive java?

use xpath type namespacecontext.

map<string, string> map = new hashmap<string, string>(); map.put("foo", "http://xmlns.oracle.com/testappln_jws/testemail/testemail"); namespacecontext context = ...; //todo: context map xpath xpath = ...; //todo: create instance mill xpath.setnamespacecontext(context); document doc = ...; //todo: parse xml string tovalue = xpath.evaluate("//foo:to", doc);

the double forwards slash makes look match first to element in http://xmlns.oracle.com/testappln_jws/testemail/testemail in given node. not matter used foo instead of ns1; prefix mapping needs match 1 in xpath expression, not 1 in document.

you can find farther examples in java: using xpath namespaces , implementing namespacecontext. can find farther examples of working soap here.

java xml soap

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -