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?

5
  • 2
    I'm not sure that is valid xml. xml documents have a root element, yours does not.
    – DaveH
    Jul 28, 2015 at 8:14
  • @DaveH Yeah, I read this before. I've tried: String inputFile = new String("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+ newline + "<root>" + newline + inputFile + newline + "</root>"); to get a root element which seems to work - probably should have mentioned that in the question!
    – Zarg
    Jul 28, 2015 at 8: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, 2015 at 8: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, 2015 at 8:31
  • @thezarg556 It seems what you are looking for is same as the solution described here - stackoverflow.com/questions/21413978/…
    – ab2000
    Aug 3, 2015 at 8:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.