• 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

Use a SAX Parser to split huge XML file into multiple parts, also need to keep the hierarchy intact

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

How can I use a SAX Parser to split a huge XML file into multiple parts (I also will need to keep the hierarchy intact):

e.g.If the input xml is:
<institution>
<institution-name>Institute-123</institution-name>
<institution-address>Institute-address</institution-address>
<departments>
<department id="101">
<employee>
<name>Emp1-101</name>
</employee>
<employee>
<name>Emp2-101</name>
</employee>
</department>
<department id="102">
<employee>
<name>Emp1-102</name>
</employee>
<employee>
<name>Emp2-102</name>
</employee>
</department>
</departments>
</institution>

The Split XMLs must list the employee names with the department & institution details(with hierarchy intact).Thus, there will be 4 xmls in this case for employees

(Emp1-101.xml)

<data>
<institution-name>Institute-123</institution-name>
<institution-address>Institute-address</institution-address>
<department id="101">
<employee>
<name>Emp1-101</name>
</employee>
</department>
</data>

Similarly we need to have XMLs for Emp2-101, Emp1-102, Emp2-102

Please note that I cannot use DOM as the input XML is very huge.

Thanks,
Amit
 
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
using Code tags to write the xml would really help...

It looks like you want us to do your home work

ok, first of all do you know how sax parsing works ?
if not, take a look at this link: http://www.java-samples.com/showtutorial.php?tutorialid=152
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As salvin francis said, your XML is hard to read, but if my assumption about your requirements is correct, you could use a series of Transformers to produce the output documents. Make their input come from an XMLFilter and just pass your SAX events on to that filter.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic