title: DOM Parser for reading XML File(edit)
body: <p>I want to read following XML file using DOM Parser.</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;CCL&gt;
      &lt;COUNTRY&gt;
         &lt;COUNTRYNAME&gt;INDIA&lt;/COUNTRYNAME&gt;
          &lt;CITY&gt;
              &lt;CITYNAME&gt;NOIDA&lt;/CITYNAME&gt;
              &lt;LOCALITY&gt;SEC 22^SEC 24^SEC 55&lt;/LOCALITY&gt;
          &lt;/CITY&gt;
          &lt;CITY&gt;
              &lt;CITYNAME&gt;DELHI&lt;/CITYNAME&gt;
              &lt;LOCALITY&gt;MAYUR VIHAR^PATPARGANJ^CHANDNI CAHUK&lt;/LOCALITY&gt;
          &lt;/CITY&gt;
      &lt;/COUNTRY&gt;
      &lt;COUNTRY&gt;
         &lt;COUNTRYNAME&gt;SINGAPORE&lt;/COUNTRYNAME&gt;
          &lt;CITY&gt;
              &lt;CITYNAME&gt;TIONG BAHRU&lt;/CITYNAME&gt;
              &lt;LOCALITY&gt;BLK 150^BLK 154^BLK 129&lt;/LOCALITY&gt;
          &lt;/CITY&gt;
          &lt;CITY&gt;
              &lt;CITYNAME&gt;TANJONG PAGAR&lt;/CITYNAME&gt;
              &lt;LOCALITY&gt;MAXWELL ROAD^CECILL STREET^AXA TOWER&lt;/LOCALITY&gt;
          &lt;/CITY&gt;
      &lt;/COUNTRY&gt;
  &lt;/CCL&gt;
  </code></pre>
  
  <p>and my java code is </p>
  
  <pre><code>public void ReadXMlFile(File f) throws ParserConfigurationException, SAXException, IOException
      {    
                  log.info("Reading log file" + f.getName() + ", from:  "+ f.getAbsolutePath());      
                  File fXmlFile = f;
                  DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
                  DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
                  Document doc = dBuilder.parse(fXmlFile);
                  doc.getDocumentElement().normalize();
  
                  log.info("Root element :" + doc.getDocumentElement().getNodeName());
                  NodeList nList = doc.getElementsByTagName("COUNTRY");
                  log.info("-----------------------");
  
                  for (int temp = 0; temp &lt; nList.getLength(); temp++) {
  
                     Node nNode = nList.item(temp);
                     if (nNode.getNodeType() == Node.ELEMENT_NODE) {
  
                        Element eElement = (Element) nNode;
  
                        log.info("COUNTRYNAME: " + getTagValue("COUNTRYNAME", eElement));
  
                          NodeList nodel= eElement.getChildNodes();
                          for(int tempcity=0; tempcity&lt; nodel.getLength() ; tempcity++)
                          {
                              Node nNode_1 = nodel.item(tempcity);
                      if (nNode_1.getNodeType() == Node.ELEMENT_NODE) {
                      Element eElement_1 = (Element) nNode_1;
  
       log.info("CITYNAME: " + getTagValue("CITYNAME", eElement));
      log.info("LOCALITY: " + getTagValue("LOCALITY", eElement));
  
                                 }
  
  
                          }
  
  
  
                     }
  
                  }
  
      }
  
  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>I m getting followin output</p>
  
  <pre><code> INFO [http-8080-1] (UtilityClass.java:41) - Root element :CCL
   INFO [http-8080-1] (UtilityClass.java:43) - -----------------------
   INFO [http-8080-1] (UtilityClass.java:52) - COUNTRYNAME: INDIA
   INFO [http-8080-1] (UtilityClass.java:61) - CITYNAME: NOIDA
   INFO [http-8080-1] (UtilityClass.java:62) - LOCALITY: SEC 22^SEC 24^SEC 55
   INFO [http-8080-1] (UtilityClass.java:61) - CITYNAME: NOIDA
   INFO [http-8080-1] (UtilityClass.java:62) - LOCALITY: SEC 22^SEC 24^SEC 55
   INFO [http-8080-1] (UtilityClass.java:61) - CITYNAME: NOIDA
   INFO [http-8080-1] (UtilityClass.java:62) - LOCALITY: SEC 22^SEC 24^SEC 55
   INFO [http-8080-1] (UtilityClass.java:52) - COUNTRYNAME: SINGAPORE
   INFO [http-8080-1] (UtilityClass.java:61) - CITYNAME: TIONG BAHRU
   INFO [http-8080-1] (UtilityClass.java:62) - LOCALITY: BLK 150^BLK 154^BLK 129
   INFO [http-8080-1] (UtilityClass.java:61) - CITYNAME: TIONG BAHRU
   INFO [http-8080-1] (UtilityClass.java:62) - LOCALITY: BLK 150^BLK 154^BLK 129
   INFO [http-8080-1] (UtilityClass.java:61) - CITYNAME: TIONG BAHRU
   INFO [http-8080-1] (UtilityClass.java:62) - LOCALITY: BLK 150^BLK 154^BLK 129
  </code></pre>
  
  <p>I want to read all entries in CITY tag for every country.</p>
  
  <p>**</p>
  
  <blockquote>
    <p>I am able to read the country tag, but I am not sure how to read CITY,
    CITYNAME for every entry of country. Please help me</p>
  </blockquote>
  
  <p>**</p>
  
  <p>Can any one help me to resolve this issue</p>