title: Parse XML using DOM in android
body: <p>Hi i want to parse XML and display list based on selection of user</p>
  
  <p>my xml is looking like this</p>
  
  <p><img src="https://i.stack.imgur.com/m1yRw.png" alt="enter image description here"></p>
  
  <p>below is my code</p>
  
  <pre><code>      try {
              XMLParser parser = new XMLParser();
              Document doc = parser.getDomElement(xml); // getting DOM element
              NodeList n1 = doc.getElementsByTagName("company");
  
              // looping through all item nodes &lt;item&gt;
              for (int i = 0; i &lt; n1.getLength(); i++) {
                  // creating new HashMap
                  Element e = (Element) n1.item(i);
  
                  System.out.println("name node "+parser.getValue(e, "name"));
              }
  </code></pre>
  
  <p>by this way i am getting the output like</p>
  
  <pre><code>  Company ABC
    Company XYZ
  </code></pre>
  
  <p>of Companies list</p>
  
  <p>but<br>
        i would write code like    </p>
  
  <pre><code>        NodeList n1 = doc.getElementsByTagName("province"); 
          // looping through all item nodes &lt;item&gt;
              for (int i = 0; i &lt; n1.getLength(); i++) {
                  // creating new HashMap
                  Element e = (Element) n1.item(i);
  
                  System.out.println("name node "+parser.getValue(e, "name"));
              }
  </code></pre>
  
  <p>i am getting list of province name </p>
  
  <pre><code>   Alberta
     Ontario
     New York
     Florida
  </code></pre>
  
  <p>but it should work like this</p>
  
  <p>when i select Company ABC</p>
  
  <p>only two provision list should display</p>
  
  <pre><code>       Alberta
         Ontario
  </code></pre>
  
  <p>not should all display can any body help me how to rewrite my code</p>