以下のようなSOAPレスポンスがあります
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<NTService.DisconnectResourceResult xmlns="http://www.evolving.com/NumeriTrack/xsd">
<retData xmlns="">
<retCode>rcSuccess</retCode>
<retMsg/>
<resErrList/>
</retData>
</NTService.DisconnectResourceResult>
</soapenv:Body>
</soapenv:Envelope>
XPATH クエリの生成が苦手ですが、SOAPUI を使用してretCode
、以下のように XPATH クエリをフェッチすることができました。
//ns1:NTService.DisconnectResourceResult[1]/retData[1]/retCode[1]/text()
Java では、フェッチしようとしてretCode
いますが、出力をフェッチできません。
XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(new SoapNamespaceContext());
String sxpath="//ns1:NTService.DisconnectResourceResult[1]/retData[1]/retCode[1]/text()";
System.out.println("sxpath is " + sxpath);
XPathExpression expr;
expr = xpath.compile(sxpath);
System.out.println("expr is " + expr);
Object result;
result = expr.evaluate(sb, XPathConstants.NODESET);
System.out.println("result is " + result);
NodeList nodes = (NodeList) result;
System.out.println("Length of result is " + nodes.getLength());
for (int i = 0; i < nodes.getLength(); i++) {
System.out.println(nodes.item(i).getNodeValue());
}
名前空間も設定しました。
public String getNamespaceURI(String prefix) {
System.out.println("Prefix is " +prefix);
if (prefix == null) throw new NullPointerException("Null prefix");
else if ("ns1".equals(prefix)) {
System.out.println("Returning http://www.evolving.com/NumeriTrack/xsd");
return "http://www.evolving.com/NumeriTrack/xsd";
}
else if ("n".equals(prefix)) {
System.out.println("Returning http://schemas.xmlsoap.org/soap/envelope/");
return "http://schemas.xmlsoap.org/soap/envelope/";
}
else if ("xml".equals(prefix)) return XMLConstants.XML_NS_URI;
return XMLConstants.NULL_NS_URI;
}
`
SOAP メッセージ応答から retCode を取得するように提案してください。
ありがとう