0
를 사용하여 SOAP 메세지를 지정하지 않고 읽어 나는 다음과 같은 SOAP 메시지가 :자바 XPath는
<?xml version="1.0" encoding="UTF-8"?>
<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"><soap:Header><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/"><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"><wsse:Username>test</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">11111111</wsse:Password></wsse:UsernameToken></wsse:Security></soap:Header>
<soap:Body xmlns:ns1="http://www.acme.co.za">
<ns1:pingMeCallback>
<ns1:message>abc</ns1:message>
</ns1:pingMeCallback>
</soap:Body>
</soap:Envelope>
내가 메시지 값에 읽을 XPath를 사용할 필요가 있습니다. 내 코드는 다음과 같습니다 :
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 < results.getLength(); i++) {
Node result = results.item(i);
XObject value = XPathAPI.eval(result, "string()");
System.out.println(value.str());
}
내 코드는 아무 것도 출력하지 않습니다. 아무도 내가 뭘하고 있는지 알아낼 수 있니?
다음과 같이 변경했습니다. root.setAttributeNS ("http://www.w3.org/2000/xmlns/", "xmlns : ns1", "hhttp : //www.acme.co.za") ; 아직도 운이 없다 – teslaza
아직도 꽤 일치하지 않습니다. 더블'h'; 또한 후행 대'/'를 검사하십시오. 네임 스페이스는 정확히 일치해야하는 문자열입니다. – bobince