Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Huge xml file into multiple xml files

 
Preethi Krishna
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic