That's quite a large file to load into memory.  I would imagine that a 
320 megabyte file is a bit larger when loaded into memory as a DOM 
structure.  You're probably still exceeding 512.  So, get more ram, 
segment your file, or use XSLT would me my suggestions.

If you wanna try to estimate how much memory you'll need, you can use 
this code and load some smaller files to get an idea:

Runtime s_runtime = Runtime.getRuntime ();
long usedMemory = s_runtime.totalMemory () - s_runtime.freeMemory ();

--Evan

Bittor Ruiz de AzĂșa wrote:
> Hi there,
>     i'm trying to parse a large xml file with dom4j and SAXReader. My code 
> works fine with small files but with the large ones (320 MB) I get a 
> "OutOfMemory" exception (Exception in thread "main" 
> java.lang.OutOfMemoryError it says). Is there any tip you can give me? I've 
> tried to execute the code giving more memory to java (with the "-mx512MB 
> option) but although it lasted for longer it finally failed. "Any help or 
> advice would be great. Thanks in advance. Cheers,
>
>
> Bittor.
>
>
> PS: This is the snippet of my code where it failes:
>
> InputStream input = 
> Test.class.getClassLoader().getResourceAsStream(batchName);   // BatchName is 
> the xml file I want to read
> BufferedInputStream bufferedStream = new BufferedInputStream(input, 32*1024);
>
> SAXReader reader = new SAXReader();
> System.out.println("Parsing XML file - Start");
> Document document = reader.read(bufferedStream);      // WITHOUT "-mx512M" it 
> fails HERE
> System.out.println("Parsing XML file - End");
>
> pictureList = document.selectNodes( "//one/two/three" );      // WITH 
> "-mx512M" it fails HERE
>
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys-and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> dom4j-user mailing list
> dom4j-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/dom4j-user
>   


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to