Reputation: 5694
I am currently using JAXB to parse XML documents, however i need a better performing XML processor.
Better = Faster and decrease memory footprint.
I have to process literally millions of separate XML documents.
I am using websphere application server v7 and java 6.
I have read Stax is the way to go via JAXP, but then i have seen articles saying JAXP is outdated.
If this is true, what are my althernatives to effeciently process millions of XML doucments (each XML doc is beteen 5Kb - 10Kb) without causing my application servers to crash with memory issues.
Upvotes: 4
Views: 19654
Reputation: 6224
You can use Groovy within Java to read xml. Create a Groovy class within your Java source dir if you are using maven
src/main/groovy
and use Groovy XMLParser to parser to parse or other class to write XML. It is much easier with Groovy to walk through the xml.
You can call the Groovy class as a Java class inside your Java program as Groovy compiles to Java class files
To do this via maven use
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>generateTestStubs</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
Upvotes: 0
Reputation: 42441
I think first of all you should track the memory issues. How many of these XML are maintained in memory simultaneously, is it possible to keep only one (or at least some fairly small amount of XMLs) in memory simultaneously? On servers Java processes usually takes at least 1Gb of memory so its not really clear whether the XML parsing is something that makes you process fail.
So I really believe you should work with a profiler here, before coming to conclusions that the XML parser should be changed.
There are a lot of parsers out there, You might try woodstox which is a stax parser. Another option can be xstream If you are looking for something that resembles JAXB, you might want to give a try to a Simple XML parser
Bottom line I believe you should first understand where does the issue exist, and if you resolve it, the chances are that you won't need to switch to another framework at all
Upvotes: 2