File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Parse large xml files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Parse large xml files" Watch "Parse large xml files" New topic
Author

Parse large xml files

Ramona Andreea
Greenhorn

Joined: Nov 22, 2008
Posts: 14
Hello,

I need some help. I want to parse a large xml which has this structure:
<start>
<node id="1" atr1="atr1" atr2="atr2"/>
<node id="2" atr1="atr1" atr2="atr2"/>
<node id="3" atr1="atr1" atr2="atr2"/>
<way id="10">
<nd ref="1"/>
<nd ref="2"/>
</way>
</start>

Foreach way tag I want to take the atr1 and atr2 values where the node id is equal with nd ref.

With SAX a can't take the childs and parents nodes. JDOM uses a lot of memory. Which library can I use to parse a very large xml with the structure above?

Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

Ramona Andreea wrote:With SAX a can't take the childs and parents nodes.

Yes you can, but you must keep track of the structure yourself. You'll probably want some stack with the current elements. Upon a start tag you push the tag to the stack, upon an end tag you pop it.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ramona Andreea
Greenhorn

Joined: Nov 22, 2008
Posts: 14
Thanks.
I thought at this, but if are a lot of childs I'll use very large stacks and for a 1GB xml it will consume a lot of memory.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parse large xml files
 
Similar Threads
Get data by Matching ID's from two different XML documents
JAXB - complex hashmap
XML DOM & children nodes
How to parse/compile XML into Java
Wats the O/P...