7 Replies Latest reply: Aug 16, 2009 3:20 PM by 3004 RSS

    heap problem parsing a XML file

    843789
      Hello,
      I have this problem; I must read a 10MB xml file and parse it but I got this problem at runtime:
      Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
      //and other message
                      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                      DocumentBuilder db = null;
                      try {
                          db = dbf.newDocumentBuilder();
                      } catch (ParserConfigurationException e) {
                          e.printStackTrace();
                      }
                      Document doc = db.parse(file);
                      doc.getDocumentElement().normalize(); // is it necessary??                                
                      NodeList nodeLst = doc.getElementsByTagName("word");
                      
                      
                      for (int s = 0; s < nodeLst.getLength(); s++) { // here crashes
       
                                  }
      I have a very long list of tag "word".
      The crach is when I try to call getLength.... How can I cope this problem.....??? Is actually here the problem or could it be in another (previous) place?

      thanks,