XML Parser
By  VcLin-IBE 发表于 2008-9-2 13:24:00 

Most current XML APIs fall into one of two broad classes: event-based APIs like SAX and XNI or tree-based APIs like DOM and JDOM. 当前的XML API分为两大类,一种是基于事件的另外是基于树的。

Most programmers find the tree-based APIs to be easier to use; but such APIs are less efficient, especially with respect to memory usage. An in-memory tree tends to be several times larger than the document it models. Thus tree APIs are normally not practical for documents larger than a few megabytes in size or in memory constrained environments such as J2ME. In these situations, a streaming API such as SAX or XNI is normally preferred. A streaming API uses much less memory than a tree API since it doesn't have to hold the entire document in memory simultaneously. It can process the document in small pieces. Furthermore, streaming APIs are fast. They can start generating output from the input almost immediately, without waiting for the entire document to be read. They don't have to build excessively complicated tree data structures they'll just pull apart again into smaller pieces. However, the common streaming APIs like SAX are all push APIs. They feed the content of the document to the application as soon as they see it, whether the application is ready to receive that data or not. SAX and XNI are fast and efficient, but the patterns they require programmers to adopt are unfamiliar and uncomfortable to many developers.大多数的程序员喜欢基于tree的,方便但是性能差,基于流的性能好,但是不友好。

Pull APIs are a more comfortable alternative for streaming processing of XML. A pull API is based around the more familiar iterator design pattern rather than the less well-known observer design pattern. In a pull API, the client program asks the parser for the next piece of information rather than the parser telling the client program when the next datum is available. In a pull API the client program drives the parser. In a push API the parser drives the client.
Pull API很舒服,它使用了iterator设计模式,而不是是observer模式。在Pull API中,程序主动请求访问下一段信息,而不是Parser准备好了,才通知你去访问。

 
阅读全文 | 回复(0) | 引用通告 | 编辑

发表评论:

    昵称:
    密码:
    主页:
    标题:

 
站点公告
友情链接
站点统计
用户登陆