Monday, 4 October 2010

Java: Cutting up a text file containing multiple XML Documents

This was put together in response to a request to handle a .txt file containing multiple XML documents (complete with XML Processing instructions). It runs through a text file (of any size really) and seeks out the start of each PI (Looking for the combination of '<' and '?' together). Each time it finds a PI it writes the content to an XML file. Not sure how useful this will be to anybody but I'm placing it here for reference anyway. It's been designed to handle text documents that look like this:

Or this:


Here's the class:

3 comments:

Girish said...

But if you have multiple
and then splitting

Anon-9323 said...

Thank you, worked like a charm!

Zakaria Boulouard said...

Beauuuuutiful! Thank you!