• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
amit bose
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • 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
 
salvin francis
Bartender
Posts: 1268
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • 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
 
Paul Clapham
Sheriff
Posts: 21001
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic