title: How to get specific XML elements with specific attribute value?
body: <p>I am trying to parse an XML file from a URL by taking all "<code>&lt;Type&gt;</code>" elements where is parameter  type_id="4218"??</p>
  
  <p>XML document:</p>
  
  <pre><code>&lt;BSQCUBS Version="0.04" Date="Fri Dec 9 11:43:29 GMT 2011" MachineDate="Fri, 09 Dec 2011 11:43:29 +0000"&gt;
    &lt;Class class_id="385"&gt;
      &lt;Title&gt;Football Matches&lt;/Title&gt;
      &lt;Type type_id="4264" type_minbet="0.1" type_maxbet="2000.0"&gt;
        ...
      &lt;/Type&gt;
      &lt;Type type_id="5873" type_minbet="0" type_maxbet="0"&gt;
        ...
      &lt;/Type&gt;
      &lt;Type type_id="4725" type_minbet="0.1" type_maxbet="2000.0"&gt;
        ...
      &lt;/Type&gt;
      &lt;Type type_id="4218" type_minbet="0.1" type_maxbet="2000.0"&gt;
        ...
      &lt;/Type&gt;
      &lt;Type type_id="4221" type_minbet="0.1" type_maxbet="2000.0"&gt;
        ...
      &lt;/Type&gt;
      &lt;Type type_id="4218" type_minbet="0.1" type_maxbet="2000.0"&gt;
        ...
      &lt;/Type&gt;
      &lt;Type type_id="4299" type_minbet="0.1" type_maxbet="2000.0"&gt;
        ...
      &lt;/Type&gt;
    &lt;/Class&gt;
  &lt;/BSQCUBS&gt;
  </code></pre>
  
  <p>Here is my Java code:</p>
  
  <pre><code> DocumentBuilder db = dbf.newDocumentBuilder();
   Document doc = db.parse(new URL("http://cubs.bluesq.com/cubs/cubs.php?action=getpage&amp;thepage=385.xml").openStream());
  
   doc.getDocumentElement().normalize();
  
   NodeList nodeList = doc.getElementsByTagName("Type");
   System.out.println("ukupno:"+nodeList.getLength());
   if (nodeList != null &amp;&amp; nodeList.getLength() &gt; 0) {
     for (int j = 0; j &lt; nodeList.getLength(); j++) {
       Element el = (org.w3c.dom.Element) nodeList.item(j);
       type_id = Integer.parseInt(el.getAttribute("type_id"));
       System.out.println("type id:"+type_id);
     }
   }
  </code></pre>
  
  <p>This code gives me all elements, I don't want that, I want all elements where the attribute type_id = "4218"!</p>