0

I am making an XML parser that needs to take multiple XML files in one go and parse them as individual files all from the same HTTP post.

The layout of them are roughly the same - here's an example of 2 of the XMLs together:

<?xml version="1.0" encoding="UTF-8"?>
<report>
    ...
</report>

<report>
    ...
</report>

I was thinking maybe some way of Java finding each instant of </report> and ultimately splitting the full XML into multiple and parsing each one separately. Is this possible using DOM and if not, is there any way this is possible in Java?

Zarg
  • 11
  • 3
  • 2
    I'm not sure that is valid xml. xml documents have a root element, yours does not. – DaveH Jul 28 '15 at 08:14
  • @DaveH Yeah, I read this before. I've tried: `String inputFile = new String(""+ newline + "" + newline + inputFile + newline + "");` to get a root element which seems to work - probably should have mentioned that in the question! – Zarg Jul 28 '15 at 08:16
  • 1
    If you add a dummy root element, you can parse it using any of the Java XML APIs (DOM/SAX/StAX). What exactly do you mean by "...parsing each one separately" - are you looking to split the processing into multiple parallel threads of execution? – ab2000 Jul 28 '15 at 08:26
  • @ab2000 Sorry, I should have been more clear. I mean it needs to accept the request filled with numerous XMLs and inevitably generate a text file or CSV with values from each XML separately, so it can be imported to Excel and each reports' element values will be in a different row. So each 'report' needs to be seen as individual to DOM so that the elements can be added to their own columns, rather than all being 1 report... – Zarg Jul 28 '15 at 08:31
  • @thezarg556 It seems what you are looking for is same as the solution described here - http://stackoverflow.com/questions/21413978/convert-an-xml-file-to-csv-file-using-java – ab2000 Aug 03 '15 at 08:27

0 Answers0