I try to parse soap response using xpath
, below the some code of response message.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:Get__CompIntfc__CI_PERSONAL_DATAResponse
xmlns:ns1="http://xmlns.oracle.com/Enterprise/Tools/schemas/M985361.V1">
<ns1:PROP_EMPLID>AA0001</ns1:PROP_EMPLID>
<ns1:PROP_LAST_NAME>Adams</ns1:PROP_LAST_NAME><ns1:PROP_FIRST_NAME>Kimberly</ns1:PROP_FIRST_NAME>
</ns1:Get__CompIntfc__CI_PERSONAL_DATAResponse >
</soapenv:Body>
</soapenv:Envelope>
I try to parse it like...
DocumentBuilderFactory domFactory =DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true);
DocumentBuilder builder = domFactory.newDocumentBuilder();
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.writeTo(out);
InputStream is = new ByteArrayInputStream( out.toByteArray() );
Document doc = builder.parse( is );
XPathExpression expr = xpath.compile("//ns1:PROP_EMPLID/text()");
Object res = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) res;
for (int i = 0; i < nodes.getLength(); i++) {
System.out.println(nodes.item(i).getNodeValue());
}
It not give the required value "AA0001"
but when i use xpath.compile("//*/text()")
it prints all text node value properly.
Please tell me what is the problem because I want some specific values from response not all text values.