开发者

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:

  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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜