I am using XMLStreamReader to achieve my goal(splitting xml file). It looks good, but still does not give the desired result. My aim is to split every node "nextTag" from an input file:
The outcome should look like this:
Referring to
http://stackoverflow.com/questions/5169978/split-1gb-xml-file-using-java I achieved my goal with this code:
Actually very simple. But, my input file is in form from a single line:
My
Java code does not produce the desired output anymore, instead just this result:
After spending hours, I am pretty sure to already find out the reason:
It is because, after the transform method being executed, the cursor will automatically moved forward to the next event. And in the code, I have this fraction:
After the first transform, the streamReader gets directly 2 times next():
1. from the transform method
2. from the next method in the while loop
So, in case of this specific line XML, the cursor can never achive the second open tag <nextTag>.
In opposite, if the input XML has a pretty print form, the second <nextTag> can be reached from the cursor because there is a space-event after the first closing tag </nextTag>
Unfortunately, I could not find anything how to do settings, so that the transformator does not automatically spring to next event after performing the transform method. This is so frustating.
Does anybody have any idea how I can deal with it? Also semantically is very welcome. Thank you so much.
Regards,
Ratna
PS. I can surely write a workaround for this problem(pretty print the xml document before transforming it, but this would mean that the input xml was being modified before, this is not allowed).