title: Multiple NameSpace in Xml Xpath value
body: <p>Am new in using Xpath parsing in Java for Xmls. But I learnt it and it worked pretty well until this below issue am not sure how to go traverse to next node in this . Please find the below code and Let me know what needs to be corrected .</p>
  
  <pre><code>package test;
  
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.transform.TransformerException;
  import javax.xml.xpath.XPath;
  import javax.xml.xpath.XPathConstants;
  import javax.xml.xpath.XPathExpressionException;
  import javax.xml.xpath.XPathFactory;
  
  import org.w3c.dom.Document;
  import org.w3c.dom.NodeList;
  
  public class CallTestcall {
      public static void main(String[] args) throws Exception {
  
          DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
          domFactory.setNamespaceAware(true);
          DocumentBuilder builder = domFactory.newDocumentBuilder();
  
          String responsePath1 = "C:/Verizon/webserviceTestTool/generatedResponse/example.xml";
          Document doc1 = builder.parse(responsePath1);
  
          String responsePath0 = "C:/Verizon/webserviceTestTool/generatedResponse/response.xml";
          Document doc0 = builder.parse(responsePath0);
  
          example0(doc0);
          example1(doc1);
      }
  
      private static void example0(Document example)
              throws XPathExpressionException, TransformerException {
          System.out.println("\n*** First example - namespacelookup hardcoded ***");
  
          XPath xPath = XPathFactory.newInstance().newXPath();
          xPath.setNamespaceContext(new HardcodedNamespaceResolver());
  
  
          String result = xPath.evaluate("s:Envelope/s:Body/ns1:UpdateSessionResponse",
                  example);
  
          // I tried all the Values to traverse further to UpdateSessionResult but am not able to I used the following xpath expressions
  
          result = xPath.evaluate("s:Envelope/s:Body/ns1:UpdateSessionResponse/a:UpdateSessionResult",
                  example);
  
          result = xPath.evaluate("s:Envelope/s:Body/ns1:UpdateSessionResponse/i:UpdateSessionResult",
                  example);
  
          System.out.println("example0 : "+result);
      }
  
      private static void example1(Document example)
              throws XPathExpressionException, TransformerException {
          System.out.println("\n*** First example - namespacelookup hardcoded ***");
  
          XPath xPath = XPathFactory.newInstance().newXPath();
          xPath.setNamespaceContext(new HardcodedNamespaceResolver());
  
          String result = xPath.evaluate("books:booklist/technical:book/:author",
                  example);
          System.out.println("example1 : "+result);
      }
  
  }
  </code></pre>
  
  <p>Please find the class that implements nameSpaceContext where I have added the prefixes</p>
  
  <pre><code>package test;
  
  import java.util.Iterator;
  import javax.xml.XMLConstants;
  import javax.xml.namespace.NamespaceContext;
  
  public class HardcodedNamespaceResolver implements NamespaceContext {
  
  
  
  /**
       * This method returns the uri for all prefixes needed. Wherever possible it
       * uses XMLConstants.
       * 
       * @param prefix
       * @return uri
       */
      public String getNamespaceURI(String prefix) {
          if (prefix == null) {
              throw new IllegalArgumentException("No prefix provided!");
          } else if (prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
              return "http://univNaSpResolver/book";
          } else if (prefix.equals("books")) {
              return "http://univNaSpResolver/booklist";
          } else if (prefix.equals("fiction")) {
              return "http://univNaSpResolver/fictionbook";
          } else if (prefix.equals("technical")) {
              return "http://univNaSpResolver/sciencebook";
          } else if (prefix.equals("s")) {
              return "http://schemas.xmlsoap.org/soap/envelope/";
          } else if (prefix.equals("a")) {
              return "http://channelsales.corp.cox.com/vzw/v1/data/";
          } else if (prefix.equals("i")) {
              return "http://www.w3.org/2001/XMLSchema-instance";
          } else if (prefix.equals("ns1")) {
              return "http://channelsales.corp.cox.com/vzw/v1/";
          } 
  
  
          else {
              return XMLConstants.NULL_NS_URI;
          }
      }
  
      public String getPrefix(String namespaceURI) {
          // Not needed in this context.
          return null;
      }
  
      public Iterator getPrefixes(String namespaceURI) {
          // Not needed in this context.
          return null;
      }
  
  }
  </code></pre>
  
  <p>Please find my Xml ::::</p>
  
  <pre><code>String XmlString  = "&lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;s:Body&gt;&lt;UpdateSessionResponse xmlns="http://channelsales.corp.cox.com/vzw/v1/"&gt;&lt;UpdateSessionResult xmlns:a="http://channelsales.corp.cox.com/vzw/v1/data/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
  &lt;a:ResponseHeader&gt;
  &lt;a:SuccessFlag&gt;true&lt;/a:SuccessFlag&gt;
  &lt;a:ErrorCode i:nil="true"/&gt;
  &lt;a:ErrorMessage i:nil="true"/&gt;
  &lt;a:Timestamp&gt;2012-12-05T15:28:35.5363903-05:00&lt;/a:Timestamp&gt;
  &lt;/a:ResponseHeader&gt;
  &lt;a:SessionId&gt;cd3ce09e-eb33-48e8-b628-ecd406698aee&lt;/a:SessionId&gt;
  &lt;a:CacheKey i:nil="true"/&gt;
  </code></pre>