XMLReader是SAX解析器,DOM解析器还是两者都不是? [英] Is XMLReader a SAX parser, a DOM parser, or neither?

查看:103
本文介绍了XMLReader是SAX解析器,DOM解析器还是两者都不是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试各种方法来读取PHP中的XML配置文件(可能很大,并且读取非常频繁).无需写作.我有两个成功的实现,一个使用 SimpleXML (我知道是DOM解析器),另一个使用 XMLReader .

I am testing various methods to read (possibly large, with very frequent reads) XML configuration files in PHP. No writing is ever needed. I have two successful implementations, one using SimpleXML (which I know is a DOM parser) and one using XMLReader.

我知道DOM读取器必须读取整个树,因此会使用更多的内存.我的测试反映了这一点.我也知道SAX解析器是一种基于事件"的解析器,它使用较少的内存,因为它从流中读取每个节点而无需检查下一步.

I know that a DOM reader must read the whole tree and therefore uses more memory. My tests reflect that. I also know that A SAX parser is an "event-based" parser that uses less memory because it reads each node from the stream without checking what is next.

XMLReader还可从流中读取带有游标的游标,该游标提供有关当前所在节点的数据.因此,听起来确实像XMLReader( http://us2.php.net/xmlreader )不是是DOM解析器,但是我的问题是,它是SAX解析器还是其他?似乎XMLReader的行为方式与SAX解析器的方式相同,但不会自行引发事件(换句话说,您可以使用XMLReader构造SAX解析器吗?)

XMLReader also reads from a stream with the cursor providing data about the node it is currently at. So, it definitely sounds like XMLReader (http://us2.php.net/xmlreader) is not a DOM parser, but my question is, is it a SAX parser, or something else? It seems like XMLReader behaves the way a SAX parser does but does not throw the events themselves (in other words, can you construct a SAX parser with XMLReader?)

如果还有其他内容,它所在的分类中是否有名称?

If it is something else, does the classification it's in have a name?

推荐答案

XMLReader 调用本身就是拉式解析器".

XMLReader calls itself a "pull parser."

XMLReader扩展是XML Pull解析器.阅读器充当光标,在文档流上前进,并在途中的每个节点处停止.

The XMLReader extension is an XML Pull parser. The reader acts as a cursor going forward on the document stream and stopping at each node on the way.

稍后会说它使用 libxml .

有关Java XML Pull Parsing的页面可能会引起人们的兴趣.如果XMLReader与该项目的目标和意图相关,那么您问题的答案将直接属于两个"类别.

This page on Java XML Pull Parsing may be of some possible interest. If XMLReader is related to this project's goals and intent, then the answer to your question falls squarely into the "neither" category.

这篇关于XMLReader是SAX解析器,DOM解析器还是两者都不是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆