title: How to read content of an xml file in Java
body: <p>I have created an XML file and DTD which can be found at the <a href="http://pastebin.com/SXc0BEUB" rel="nofollow">HERE</a>.</p>
  
  <p>I have written a code, but it works till one level, then it doesnot works properly. I have also created certain objects to store the value of the xml file. But i am only able to traverse till <code>sheet</code> tag of the xml, then it doesnot works properly.</p>
  
  <pre><code>Recon recon = new Recon();
  
  DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
  DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
  Document doc = dBuilder.parse(configFile);
  doc.getDocumentElement().normalize();
  
  System.out.println("Root Element : " + doc.getDocumentElement().getNodeName());
  String outputPath = doc.getDocumentElement().getAttribute("outputPath");
  String withCompareFilePath = doc.getDocumentElement().getAttribute("withCompareFile");
  String toCompareFilePath = doc.getDocumentElement().getAttribute("toCompareFile");
  
  recon.setOutputPath(outputPath);
  recon.setToCompareFile(new File(toCompareFilePath));
  recon.setWithCompareFile(new File(withCompareFilePath));
  
  NodeList sheetNodeList = doc.getElementsByTagName("sheet");
  
  List&lt;ReconSheet&gt; reconSheets = new ArrayList&lt;ReconSheet&gt;();
  
  for(int i = 0; i&lt; sheetNodeList.getLength() ; i++) {
    Node tempNode = sheetNodeList.item(i);
    ReconSheet reconSheet = new ReconSheet();
    NamedNodeMap attMap = tempNode.getAttributes();
    Node sheetNode = attMap.getNamedItem("sheetNumber");
    String sheetNumber = sheetNode.getNodeValue();
    reconSheet.setSheetNumber(Integer.parseInt(sheetNumber));
    NodeList list = tempNode.getChildNodes();
    for(int j = 0; j&lt; list.getLength(); j++) {
      Node inNode = list.item(j);
      System.out.println(inNode);
    }
  }
  </code></pre>