tags:

views:

21

answers:

2

when should i go for Expat parser rather Dom Parser and vice versa ? What is the difference between these parsers ?

A: 

The xml_parser_ functions give you a stream of SAX-style callbacks as the file is consumed. It's up to you to handle or store them appropriately as they come in, linearly in document order.

(XMLReader is another serial-access parser with an imperative rather than event-based interface, which can be useful particularly for more rigidly-defined data formats.)

The DOMDocument loaders read the entire XML content into memory and give you a simple object-like means of querying any part of the document. For random-access tasks this is much easier to cope with, but it's also much less efficient for large documents.

bobince
A: 

Expat is a SAX parser.

Here's a comparison between SAX and DOM parser

SAX:

  1. Does not load the XML into memory

  2. Top to bottom traversing

  3. Event driven and works incrementally.

DOM:

  1. Loads XML into memory. Hence occupies more memory.

  2. Traverse in any direction.

deepsat