• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Huge xml file into multiple xml files

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Nothing up my sleeve ... and ... presto! A tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic