[jdom-interest] out of memory while processing large xml files

prakash ivb prakashivb at usa.net
Fri Jan 19 12:18:00 PST 2001


hai,

              i am trying to parse multiple xml files with each file of 20M
size and i am getting out of memory error. is there any way i can solve my
problem. the code is given below:


import java.io.*;
import java.util.*;
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;
import org.jdom.JDOMException;

class extn implements FilenameFilter {
  String ext;
  public extn (String ext) {
    this.ext = "." + ext;
  }
  public boolean accept(File dir, String name) {
    return name.endsWith(ext);
  }
}

public class JdomParser {
  
  public static void main(String args[]) {
    if (args.length !=1) {
       System.out.println("Usage: JdomParser [filename to parse]");
       return;
     }
     try {
    String dirname = "n:"+File.separator+"data"+File.separator + args[0] +
File.separator+ "rawdata";
   File f = new File(dirname);
    FilenameFilter files = new extn("xml");
    String s3[] = f.list(files);
    int ct = 1;
       System.out.println("Parsing Begins at " + d + "\n");
       for (int k=0; k<s3.length;k++) {
         SAXBuilder builder = new SAXBuilder(false);
	Document doc =  builder.build(new File(f, s3[k]));
	System.out.println("Parsing File:  " + s3[k] + "\n"); 
       Element root = doc.getRootElement();
       List node = root.getChild("Collection")
                        .getChild("Iteration")
                        .getChildren("Device");
      
       Iterator i = node.iterator();
       while (i.hasNext()) {
         Element elem = (Element)i.next();
	       String s = elem.getChild("Node")
	               .getText();
         System.out.println("Parsing No. " + ct + "   Node: " + s + "\n");
        List command = elem.getChildren("Command");
         Iterator j = command.iterator();
         System.out.println("    Parsing Commands... \n");
         int ct1 = 1;
         while (j.hasNext()) {
           Element comelem = (Element)j.next();
           String s1 = comelem.getChild("Command_String").getText();
           String s2 = comelem.getChild("Command_Data").getText();
           System.out.println("    " +ct1 +" : " + s1 + "\n");
           System.out.println("        Parsing Command Data...\n");
           ct1++;
         }
	       ct++;
       }
       System.out.println("Document " + s3[k] + " successfully parsed\n");
       ct = 1;
     }
             
     } catch (JDOMException e) {
        System.out.println( "ERROR: " + e.getMessage());
       }
   }
   
}
i will appreciate you help.


prakash Inuganti



____________________________________________________________________
Get free email and a permanent address at http://www.netaddress.com/?N=1



More information about the jdom-interest mailing list