W3C home > Mailing lists > Public > xmlschema-dev@w3.org > August 2009

Not able to fetch multiple elements from soap response using xpath

From: sridhar veerappan <sriasarch@gmail.com>
Date: Tue, 4 Aug 2009 15:19:48 +0530
Message-ID: <d33701630908040249g530b634t6b3d8631c7abac54@mail.gmail.com>
To: xmlschema-dev@w3c.org
Cc: priscilla@walmsley.com, saul@syncline.com

I am new to xpath, I am using xpath to get the data dynamically from soap

Soap Response:
<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
      <ns1:getClosestPaymentCenterResponse xmlns:ns1="http://test.com">

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),

    public Document getDocumentFromFile(String fName) throws Exception {

          DocumentBuilderFactory dbFactory =
          //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();

I need to get only Code, Address and City.How to get the data using xpath?

Thanks in Advance
Received on Wednesday, 5 August 2009 11:43:37 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:56:16 UTC