title: How to read XML parent node tag value in android
body: <p>I have a java code to read XML nodes, I want to add in the addition and want to read the parent node value also.</p>
  
  <p>my XML file  sample is below:</p>
  
  <pre><code> &lt;breakfast_menu&gt;&lt;food id=1&gt;&lt;name&gt; Belgian Waffles &lt;/name&gt;&lt;price&gt; $5.95 &lt;/price&gt;&lt;description&gt; two of our famous Belgian Waffles with plenty of real maple syrup &lt;/description&gt;&lt;calories&gt; 650 &lt;/calories&gt;&lt;/food&gt;&lt;food id=2&gt;&lt;name&gt;Strawberry Belgian waffles&lt;/name&gt;&lt;price&gt;$7.95&lt;/price&gt;&lt;description&gt;light Belgian waffles covered with strawberries and whipped cream&lt;/description&gt;&lt;calories&gt;900&lt;/calories&gt;&lt;/food&gt;&lt;/breakfast_menu&gt;
  </code></pre>
  
  <p>and my code for parsing xml is :</p>
  
  <pre><code>public static String getProductItem(String pid, String item) {
  
      try {
          url = new URL("");
          urlConnection = url.openConnection();
      } catch (MalformedURLException e) {
          e.printStackTrace();
      } catch (IOException e) {
  
      }
  
      try {
          dBuilder = dbFactory.newDocumentBuilder();
      } catch (ParserConfigurationException e) {
      }
      try {
          doc = dBuilder.parse(urlConnection.getInputStream());
      } catch (SAXException e) {
  
      } catch (IOException e) {
  
      }
  
      doc.getDocumentElement().normalize();
  
      NodeList nList = doc.getElementsByTagName("food");
  
      for (int temp = 0; temp &lt; nList.getLength(); temp++) {
  
          Node nNode = nList.item(temp);
  
          if (nNode.getNodeType() == Node.ELEMENT_NODE) {
  
              Element eElement = (Element) nNode;
  
  
  
                  data = getTagValue(item, eElement);
  
  
  
          }
      }
  
      doc = null;
      dBuilder = null;
  
      return data;
  
  }
  
  
  private static String getTagValue(String sTag, Element eElement) {
      NodeList nlList = eElement.getElementsByTagName(sTag).item(0)
      .getChildNodes();
      Node nValue = (Node) nlList.item(0);
  
      return nValue.getNodeValue();
  }
  </code></pre>
  
  <p>What I want to do is to read the "id" value of food, so if if I am searching for a food, it only checks those food nodes, whose id matched the food node id.</p>
  
  <p>if I read by tag id, it reads all tags not specifically one tag. How to achieve it?</p>