title: How to read XML child node values of specific element?
body: <p>I am trying to read child node value with attribute value of a specific element using DOM parser..
  My xml file:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;RootNode&gt;
      &lt;SubNode Sid="1"&gt;
          &lt;title&gt;some text&lt;/title&gt;
          &lt;data dId="1"&gt;some text&lt;/data&gt;
          &lt;data dId="2"&gt;some text&lt;/data&gt;
          &lt;ExData&gt;1&lt;/ExData&gt;
      &lt;/SubNode&gt;
      &lt;SubNode Sid="2"&gt;
          &lt;title&gt;some text&lt;/title&gt;
          &lt;data dId="1"&gt;some text&lt;/data&gt;
          &lt;data dId="2"&gt;some text&lt;/data&gt;
          &lt;data dId="3"&gt;some text&lt;/data&gt;
          &lt;data dId="4"&gt;some text&lt;/data&gt;
          &lt;data dId="5"&gt;some text&lt;/data&gt;
          &lt;ExData&gt;1&lt;/ExData&gt;
      &lt;/SubNode&gt;
      &lt;SubNode Sid="3"&gt;
          &lt;title&gt;some text&lt;/title&gt;
          &lt;data dId="1"&gt;some text&lt;/data&gt;
          &lt;data dId="2"&gt;some text&lt;/data&gt;
          &lt;data dId="3"&gt;some text&lt;/data&gt;
          &lt;ExData&gt;1&lt;/ExData&gt;
      &lt;/SubNode&gt;
  &lt;/RootNode&gt;
  </code></pre>
  
  <p>i am trying to read <code>data</code> nodes value of a one <code>SubNode</code>. i have checked with below code:</p>
  
  <pre><code>private void parseDocument()
  {
      Element docEle = dom.getDocumentElement();
      NodeList nl = docEle.getElementsByTagName("SubNode");
      if(nl!= null &amp;&amp; nl.getLength()&gt;0)
      {
          for(int i=0; i&lt;nl.getLength();i++)
          {
              Element el = (Element)nl.item(i);
              InfoBean que = getInfoBean(el);
              InfoBeanSet.add(que);
          }
      }
  }
  private InfoBean getInfoBean(Element el)
  {
      int sId = Integer.parseInt(el.getAttribute("Sid"));
      String title = getTextValue(el,"title");    
  
      NodeList SingleOptionNode = el.getElementsByTagName("data");
      int nodeLen = SingleOptionNode.getLength();
      if(SingleOptionNode != null &amp;&amp; nodeLen&gt;0)
      {
          for(int i=0; i&lt;nodeLen; i++)
          {
              Element el1 = (Element)SingleOptionNode.item(i);
              NodeList nextOption = el1.getChildNodes();
              Node currentNode = (Node) nextOption.item(0);
              int dId = Integer.parseInt(el1.getAttribute("dId"));
              String data = currentNode.getNodeValue();
              opt.add(new Option(data, dId));
          }
      }
      String ExData = getTextValue(el,"ExData");
      InfoBean ifb = new InfoBean(sId,title,opt,ExData);
      return ifb;
  }
  </code></pre>
  
  <p>it gives data node values of all 3 SubNodes. how to read one SubNode element child node values with attribute value.
  Can i know the reason why am getting all data node value?
  can i get some code examples how to read data node value of a one SubNode element..
  Any help would appreciated.</p>