views:

201

answers:

3

Hi I have heard a lot about XML parser but I want to know i.e 2 kinds of it and also the advantages and disadvantages of each one! please help me thanks

+3  A: 

There's a nice article comparing Sax vs Dom XML parsers.

  • Sax: very fast and works for huge documents but the API is less intuitive as it is event based
  • Dom: slower and more memory consuming because the whole XML needs to be loaded into memory but the API is very easy to use.
Darin Dimitrov
thanks for your answer and the good link!
Johanna
You forgot one: Writing your own - normally handles only small special cases, usually a nightmare to maintain and extend, and reinvents the wheel! eg: http://thedailywtf.com/Articles/What-Could-Be-Easier-Than-XML.aspx
CuriousPanda
A: 

Kind of a broad question. I suppose the two main approaches are DOM and SAX parsers.

DOM parsers create an in-memory tree of nodes for the document. Very easy to use for the programmer, but could be too much overhead for large documents.

SAX parsers read through the document once and create a stream of events like "tag started". It is up the programmer to do useful things with these events. More efficient, but more difficult to use.

Thilo
thanks for your answer!
Johanna
A: 

There are two more worth investigating:

1.StaX: easier to use than SAX http://www.xml.com/pub/a/2003/09/17/stax.html

2.VTD-XML: faster and leaner than DOM http://java.dzone.com/articles/introduction-vtd-xml

vtd-xml-author
Note that Mr. Zhang is the author of VTD-XML.
John Saunders