title: XPath Java count of child nodes
body: <p>I want to count some child nodes of a given xml. But it always returns me 0 and I can't figure out why.</p>
  
  <p>Here's the xml:</p>
  
  <pre><code>&lt;FirstOne xmlns:xxx="http://www.w3.org/2001/XMLSchema-instance"&gt;
    &lt;Formulas xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"&gt;
      &lt;xxx:yyy&gt;
        &lt;aa:bb&gt;something&lt;/aa:bb&gt;
        &lt;cc:dd&gt;something&lt;/cc:dd&gt;
      &lt;/xxx:yyy&gt;
      &lt;xxx:yyy&gt;
        &lt;aa:bb&gt;something&lt;/aa:bb&gt;
        &lt;cc:dd&gt;something&lt;/cc:dd&gt;
      &lt;/xxx:yyy&gt;
      &lt;xxx:yyy&gt;
        &lt;aa:bb&gt;something&lt;/aa:bb&gt;
        &lt;cc:dd&gt;something&lt;/cc:dd&gt;
      &lt;/xxx:yyy&gt;
    &lt;/Formulas&gt;
  
  &lt;/FirstOne&gt;
  </code></pre>
  
  <p>I want to count the number of "xxx:yyy". In this example 3.
  I tried the following:</p>
  
  <pre><code>    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      dbf.setValidating(false);
      DocumentBuilder db = dbf.newDocumentBuilder();
      Document doc = db.parse(new FileInputStream(new File(fileArray[i].toString())));
      XPathFactory factory = XPathFactory.newInstance();
      XPath xpath = factory.newXPath();
      String expression;
      expression = "count(//Formulas/xxx:yyy)";
      Double result = (Double) xpath.evaluate(expression, doc, XPathConstants.NUMBER);
  </code></pre>
  
  <p>It always gives me 0.0 ...</p>
  
  <p>Thanks for your help!</p>