File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Huge xml file into multiple xml files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Huge xml file into multiple xml files" Watch "Huge xml file into multiple xml files" New topic
Author

Huge xml file into multiple xml files

Preethi Krishna
Greenhorn

Joined: May 13, 2009
Posts: 11
Hi All,

I have an xml file like

<root>
<a/>
<b/>
<c>
<c1>x</c1>
<c2>y</c2>
</c>
<c>
<c1>t</c1>
<c2>v</c2>
</c>
<c>
<c1>x</c1>
<c2>t</c2>
</c>
<c>
<c1>y</c1>
<c2>c</c2>
</c>
</root>


which has to be chunked into xmlfiles based on c1 values

<root>
<a/>
<b/>
<c>
<c1>x</c1>
<c2>y</c2>
</c>
<c>
<c1>x</c1>
<c2>t</c2>
</c>
</root>

<root>
<a/>
<b/>
<c>
<c1>t</c1>
<c2>v</c2>
</c>
</root>

<root>
<a/>
<b/>
<c>
<c1>y</c1>
<c2>c</c2>
</c>
</root>


I haven't used stax before and know little about xquery/xpath. Can you please give me suggestions on which one to use and some guidance to use? and the input xml can be more than 50mb.

Thanks for your help
Preethi
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
This certainly looks like a job for a SAX or StAX parser in order to not worry about memory consumption.

XPath only works with DOM so that is right out.

You will need to figure out a way (probably a custom class) to hold all of the information inside a <c> element until you can decide which output file gets the content.

I would certainly work ENTIRELY in text - no need to get tangled up with building DOMs.

I suggest you review the relevant chapters in Harold's free online book.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Huge xml file into multiple xml files