Expat Parser vs Dom Parser in php
when should i go for Expat parser rather Dom Parser and vice versa ? What is the difference between 开发者_JAVA百科these parsers ?
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.
Expat is a SAX parser.
Here's a comparison between SAX and DOM parser
SAX:
Does not load the XML into memory
Top to bottom traversing
Event driven and works incrementally.
DOM:
Loads XML into memory. Hence occupies more memory.
Traverse in any direction.
精彩评论