title: Checking if particular node exists in Xml file using Xpath
body: <p>I would like to check is <code>code = "ABC" </code>  exists in my xml file using xPath.Can you please suggest me some methods for it? </p>
  
  <pre><code>&lt;metadata&gt;
   &lt;codes class = "class1"&gt;
        &lt;code code = "ABC"&gt;
              &lt;detail "blah blah"/&gt;
          &lt;/code&gt;
    &lt;/codes&gt;
    &lt;codes class = "class2"&gt;
        &lt;code code = "123"&gt;
              &lt;detail "blah blah"/&gt;
          &lt;/code&gt;
    &lt;/codes&gt;
   &lt;/metadata&gt;
  </code></pre>
  
  <p>[EDIT]
  I did following. It reuturns null.</p>
  
  <pre><code>            XPath xPath = XPathFactory.newInstance().newXPath();
              XPathExpression expr = xPath.compile("//codes/code[@ code ='ABC']");
              Object result = expr.evaluate(doc, XPathConstants.NODESET);
  
              NodeList nodes = (NodeList) result;
              for (int i = 0; i &lt; nodes.getLength(); i++) {
                  System.out.println("nodes: "+ nodes.item(i).getNodeValue()); 
              }
  </code></pre>