Well, firstly, I want to thank two people who answer my questions, but I did not use these suggestions in the end, partly because the proposed technologies are a bit far from Java, let them say "standard XML parsing", and it feels weird as long as there is a similar tool already present in Java, and partly also because I actually found a solution that uses the Java API to accomplish this.
I will not describe in detail the solution that I found, because I have already completed the implementation, and here is a rather large piece of code (I use Spring Batch on top of everything, with a ton configuration, etc.).
However, I will make a short comment about the fact that I finally finished:
The big idea here is that if you have an XML document and an appropriate XSD schema, you can parse and sort it with JAXB, and you can do it in chunks, and these chunks can be read using an even parser such as STAX and then passed to JAXB marshaller.
This practically means that you must first decide where is a good place in your XML file, where you can say: "This part here contains a lot of repeating structure, I will process these repetitions one at a time." These repeating parts are usually the same (child) tags, repeatedly repeating within the parent tag. So, all you have to do is make an event listener in your STAX parser that runs at the beginning of each of these child tags, and not pass the contents of that child tag to JAXB, sort it with JAXB and process it.
In fact, the idea is excellently described in this article, which I followed (although this is from 2006, but it is about JDK 1.6, which at that time was quite new, so the version is essentially not that old):
http://www.javarants.com/2006/04/30/simple-and-efficient-xml-parsing-using-jaxb-2-0/