title: Search a particular string in XML file using Stax
body: <p>I'm trying to check whether particular 2 strings are present in an XML file or not.</p>
  
  <p>The xml code</p>
  
  <pre><code>&lt;datapoint nature="PARAMETRIC" division="COLL_COMP_ENG" programmaticName="t_val_calc_enrg_accumulated" /&gt;
  &lt;datapoint nature="PARAMETRIC" division="COLL_COMP_ENG" programmaticName="t_val_calc_pwr_consumed" /&gt;
  </code></pre>
  
  <p>Java code..</p>
  
  <pre><code>    Integer count=0;
      XMLInputFactory f = XMLInputFactory.newInstance();
       XMLStreamReader rdr = f.createXMLStreamReader(new FileReader("E:\\SVN\\MasterData\\MasterData.xml"));
  
        while (rdr.hasNext()) {
        if (rdr.next() == XMLStreamConstants.START_ELEMENT) {
        if (rdr.getLocalName().equals("datapoint")) {
             String txt = rdr.getAttributeValue("programmaticName");
              if (txt.indexOf("t_val_calc_pwr_consumed") &gt; 0 || txt.indexOf("t_val_calc_enrg_accumulated") &gt; 0) {
                System.out.println(txt);
                count++;
              }
         }
    }
    }
  System.out.println(count);
  </code></pre>
  
  <p>Whenever i try to run the code i get an error message   "String cannot be converted to int" for the line.</p>
  
  <pre><code>  String txt = rdr.getAttributeValue("programmaticName");  
  </code></pre>
  
  <p>The stacktrace is</p>
  
  <pre><code>     Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: javax.xml.stream.XMLStreamReader.getAttributeValue
  at sample.eXTRACT.main(eXTRACT.java:42)
       Java Result: 1
       BUILD SUCCESSFUL (total time: 2 seconds)
  </code></pre>
  
  <p>The expected output:</p>
  
  <pre><code>   t_val_calc_enrg_accumulated
     t_val_calc_pwr_consumed
  </code></pre>