• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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
 
Honk if you love justice! And honk twice for tiny ads!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic