 |
 |
 |
Hi,
I am new to xpath, I am using xpath to get the data dynamically from soap
response.
Soap Response:
<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<ns1:getClosestPaymentCenterResponse xmlns:ns1="http://test.com">
<ns1:getClosestPaymentCenterResult>
<ns1:Code>1</ns1:Code>
<ns1:Message>test</ns1:Message>
</ns1:getClosestPaymentCenterResult>
<ns1:paymentCenter>
<ns1:ID>111</ns1:ID>
<ns1:Name>Sri</ns1:Name>
<ns1:Address>SUITE</ns1:Address>
<ns1:City>BLORE</ns1:City>
</ns1:paymentCenter>
</ns1:getClosestPaymentCenterResponse>
</soapenv:Body>
Java Code:
public void xpathTest(String xmlFile) throws Exception {
XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression expr = xpath.compile("//*[name()='ns1:ID']/text()");
Object result = expr.evaluate(getDocumentFromFile(xmlFile),
XPathConstants.STRING);
System.out.println("ID:"+result);
}
public Document getDocumentFromFile(String fName) throws Exception {
DocumentBuilderFactory dbFactory =
DocumentBuilderFactory.newInstance();
//dbFactory.setNamespaceAware(true); // never forget this!
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
return dBuilder.parse(new File(fName));
}
public static void main(String[] args) throws Exception {
XPathTest test = new XPathTest();
test.xpathTest("D:/transform/ClosestPaymentCenter.xml");
}
I need to get only Code, Address and City.How to get the data using xpath?
Thanks in Advance
Sri
|
 | 

|  |
These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.
|  |
| |
 |
 |
 |