开发者

when does XPathExpression.evaluate throw?

Going through the XPath.compile API, I was under the impression that it would return a valid XPathExpression or throw.

Indeed, it doesn't make sense that any compiler would return an object that is not 'runnable'.

Therefore I was a little surprised that a valid XPathExpression could still throw when evaluateing a document, especially since according to it's description,

XPathExpressionException represents an error in an XPath expression

Does that make sense? Can a c开发者_如何学Compiled expression still have an error?


A static error in an XPath expression (for example incorrect XPath syntax, or a reference to an undefined function, variable, or namespace) will throw an error from the compile() method.

A dynamic error in an XPath expression will throw an exception from the evaluate() method.

XPath 1.0 is designed to have very few dynamic errors. An example of one would be count(3), which is an error because count() can only be applied to a node-set. In XPath 2.0 there are many more dynamic errors possible.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜