HTML5 Canvas
Written by: Simon Sarris
Featured Refcardz: Top Refcardz:
  1. Apache Hadoop
  2. Web Driver
  3. MVVM
  4. REST
  5. ADO.NET
  1. HTML5
  2. Ajax
  3. jQuery Selectors
  4. CSS Part 1
  5. Git

Link Details

Link 300905 thumbnail
User 131196 avatar

By jj83777
via tutorials.jenkov.com
Published: Nov 23 2009 / 11:44

This text compares Java's two stream oriented XML parsers, SAX and StAX, and explains the difference in a "push" model and "pull" model. It also lists other differences in these two API's. If you have ever wondered which of these two API's to use, this text may help you decide.
  • 12
  • 0
  • 3650
  • 3

Comments

Add your comment
User 368023 avatar

yakkoh replied ago:

0 votes Vote down Vote up Reply

Questions:
why event, why not token or doohickey or thing?
why is it so complicated?
why no open and close methods? XML is not a stream?

User 131196 avatar

Jakob Jenkov replied ago:

0 votes Vote down Vote up Reply

I don't know :-) I didn't write the API's. But you are right, sometimes XML processing seems a bit more complicated than it should be.

User 466155 avatar

anon2 replied ago:

0 votes Vote down Vote up Reply

XML is actually not ideally suited for stream processing, because without loading the entire document in memory, a lot of context information is lost

VTD-XML is better suited for processing XML than DOM and SAX

User 455317 avatar

jeffb replied ago:

1 votes Vote down Vote up Reply

Most of the time I don't use sax, or stax because they're more complex to use than a few open source libraries I've found.

I use xstream to map objects to xml.
http://xstream.codehaus.org

When I am processing xml and I can't bind it my preferred library is XOM.
http://www.xom.nu/

Both xstream, and xom can process xml in parts so all the xml doesn't need to be in ram at once.

There is also jdom which is another tree based xml api that you may want to check out (personally I prefer xom but you may like jdom more).
http://www.jdom.org/

User 466155 avatar

anon2 replied ago:

0 votes Vote down Vote up Reply

xom and jdom all suffer from excessive memory usages due to object allocations

User 131196 avatar

Jakob Jenkov replied ago:

0 votes Vote down Vote up Reply

Thanks a lot for all of these interesting comments. It is always inspiring to see new ways of doing "the same". There are so many XML frameworks (and Java frameworks in general) that it can be really hard to go through all of them one by one.

User 131196 avatar

Jakob Jenkov replied ago:

0 votes Vote down Vote up Reply

By the way, I prefer DOM4J over JDOM any time. Better performance, and it seems to be more flexible too.

User 466155 avatar

anon2 replied ago:

1 votes Vote down Vote up Reply

DOM4J is not match for vtd-xml, (10x faster in a typical use case)

User 131196 avatar

Jakob Jenkov replied ago:

0 votes Vote down Vote up Reply

Interesting - I'll have to check out that vtd-xml :-) ... sounds promising!

User 190897 avatar

unkind replied ago:

1 votes Vote down Vote up Reply

i totally agree with anon2 vtd-xml is very fast (5 x to 12x faster than jdom)

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (12)



Voters Against This Link (0)