2

I need to use a xml pull parser. I can find stax-api.jar which seems to be already part of com.sun.xml.* and it seems that there is already something stax related implemented.

com.sun.xml unfortunately has no sources in JDK 6, so I can't tell.

Also there are xmlpull, stax.codehaus.org and apache axiom, that kinda implements stax-api. stax.codehaus.org seems to be a stax reference implementation. Xmlpull seems to be done by the same people as the reference implementation and Apache Axiom seems to be a StAX based parser that was created for Apache Axis2.

Could you please clarify what are the main differences, what API to use and when would you use one of these implementations and why ?

Edit: Before you decide to close this question, notice that xmlpull.org and stax.codehaus.org releases are pretty old (5 years) and one really can't say if the stax parser implementation is part of sun.com.xml.*. I'd just need someone with pull parser experience to tell me, what to use and why.

For instance, Apache Abdera project (I'm parsing atom feeds too) is using Axiom implementation that seems to be implementing its Axiom-api and also geronimo-stax-api_1.0_spec

StaxMan
  • 113,358
  • 34
  • 211
  • 239
lisak
  • 21,611
  • 40
  • 152
  • 243
  • Used XMLPull back in 2005 and it was bloody fast, bloody small. Great tool at the time. Can't speak for now because it hasn't been updated in awhile. Apache Axiom appears to have picked up where XMLPull left off. You could also take a look at WoodStox. – Perception Oct 07 '11 at 19:32
  • "_Hey, I was not asking WHAT type of parser to use. I was asking what implementation of PULL Parser to use_". Ok, it was not obvious from the _first_ draft of your question. – tolitius Oct 07 '11 at 19:56
  • the tag xmlpullparser didn't change and the title "what pull parser implementation to use" also didn't change... So I thing it was obvious enough, but I suppose that it was also quite easy to miss that and misinterpret the question... – lisak Oct 07 '11 at 20:04

2 Answers2

3

Aside from pointing out that JDK/JRE bundles Sun's SJSXP which works ok at this point, I would recommend AGAINST using Stax ref impl (stax.codehaus.org) -- do NOT use it for anything, ever. It has lots of remaining bugs (although many were fixed, initial versions were horrible), isn't particularly fast, doesn't implement even all mandatory features. Stay clear of it.

I am partial to Woodstox, which is by far the most complete implementation for XML features (on par with Xerces, about the only other Java XML parser that can say this), more performant than Sjsxp, and all around solid parser and generator -- this is why most modern Java XML web service frameworks and containers bundle Woodstox.

Or, if you want super-high performance, check out Aalto. It is successor to Woodstox, with less features (no DTD handling) but 2x faster for many common cases. And if you ever need non-blocking/async parsing (for NIO based input for example), Aalto is the only known Java XML parser to offer that feature.

As to Axiom: it is NOT a parser, but tree model built on top of Stax parser like Woodstox, so they didn't reinvent the wheel. XmlPull predates Stax API by couple of years; basically Stax standardization came about people using XmlPull, liking what they saw, and Sun+BEA wanting to standardize the approach. There was some friction in the process, so in the end XmlPull was not discontinue when Stax was finalized, but one can think of Stax as successor -- XmlPull is still used for mobile devices; I think Android platform includes it.

(disclaimers: I am involved in both Aalto and Woodstox projects; as well as provided more than a dozen bug fixes to both SJSXP and Stax RI)

StaxMan
  • 113,358
  • 34
  • 211
  • 239
1

As of Java 1.6, there is a StaX implementation inside the plain bundled JRE. You can use that. If you don't like the performance, drop in woodstox.

Axiom is something else entirely, much more complex. Xmlpull seems to be going by the wayside in favor of one Stax implementation or another.

bmargulies
  • 97,814
  • 39
  • 186
  • 310
  • thanks, woodstox is the best option for me, I missed that, because it has org.codehaus.stax2 fqn and uses wstx shortcut and google didn't show much about it. – lisak Oct 07 '11 at 20:11
  • Btw, I really don't see the implementation in JRE, if I search for classes that implements stax-api, mostly there is none in JRE, and sometimes in com.sun.xml.internal.fastinfoset.stax.* ... But for instance MXParser is part of xmlpull.org as well as stax.codehaus.org ... only codehaus implementation implements stax-api though – lisak Oct 07 '11 at 20:16
  • It's there. You just call newInstance on the factories and it works. – bmargulies Oct 07 '11 at 20:17
  • 1
    http://download.oracle.com/javase/6/docs/api/javax/xml/stream/XMLInputFactory.html is there, and you call createXMLStreamReader. – bmargulies Oct 07 '11 at 20:19