开发者

Which XML parser API does dom4j SaxReader use? SAX or DOM?

In dom4j website it says "SAXReader creates a DOM4J tree from SAX parsing events.". What does this mean? Is SAXReade开发者_JAVA百科r a DOM parser that creates a tree of the full XML file, or does it process the XML document sequentially like a SAX parser?

Question 2: I can use XPath queries in SAXReader. Is XPath compatible with SAX or DOM parsers?


The whole point of dom4j is that it is an alternative tree model to DOM. It wouldn't make any sense to parse a whole DOM only to convert it to dom4j. Anyway this page makes it clear that a SAX parser is used to generate a dom4j.

Re: your XPath question. Generally speaking you do need a tree model to run XPath against. This means something like DOM, dom4j, jdom, or xom. These are all various different "xml document object models". SAX is a different thing altogether - it is just a stream of events with no object model. So the correct mental model is: use a SAX parser to generate an object model, and then run XPath against that object model. Of course there are other things you can do, but that is one natural way those three technologies can fit together.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜