nsIDOMXPathEvaluator 编辑

dom/interfaces/xpath/nsIDOMXPathEvaluator.idlScriptable This interface is used to evaluate XPath expressions against a DOM node. Inherits from: nsISupports Last changed in Gecko 1.7

Implemented by: @mozilla.org/dom/xpath-evaluator;1. To create an instance, use:

var domXPathEvaluator = Components.classes["@mozilla.org/dom/xpath-evaluator;1"]
                        .createInstance(Components.interfaces.nsIDOMXPathEvaluator);

Method overview

nsIDOMXPathExpression createExpression(in DOMString expression, in nsIDOMXPathNSResolver resolver)
nsIDOMXPathNSResolver createNSResolver(in nsIDOMNode nodeResolver);
nsISupports evaluate(in DOMString expression, in nsIDOMNode contextNode, in nsIDOMXPathNSResolver resolver, in unsigned short type, in nsISupports result)

Methods

createExpression()

Creates an nsIDOMXPathExpression which can then be used for (repeated) evaluations.

Note: Prior to Gecko 1.9, you could call this method on documents other than the one you planned to run the XPath against; starting with Gecko 1.9, however, you must call it on the same document.

 nsIDOMXPathExpression createExpression(
   in DOMString expression,
   in nsIDOMXPathNSResolver resolver
 );
Parameters
expression
A string representing the XPath to be created.
resolver
A name space resolver created by createNSResolver(), or a user defined name space resolver. Read more on Implementing a User Defined Namespace Resolver if you wish to take the latter approach.
Return value

An XPath expression, as an nsIDOMXPathExpression object.

createNSResolver()

Creates an nsIDOMXPathExpression which resolves name spaces with respect to the definitions in scope for a specified node. It is used to resolve prefixes within the XPath itself, so that they can be matched with the document. null is common for HTML documents or when no name space prefixes are used.

nsIDOMXPathNSResolver createNSResolver(
  in nsIDOMNode nodeResolver
);
Parameters
nodeResolver
The node to be used as a context for name space resolution.
Return value

A name space resolver.

evaluate()

Evaluate the specified XPath expression.

nsISupports evaluate(
  in DOMString expression,
  in nsIDOMNode contextNode,
  in nsIDOMXPathNSResolver resolver,
  in unsigned short type,
  in nsISupports result
);
Parameters
expression
A string representing the XPath to be evaluated.
contextNode
A DOM Node to evaluate the XPath expression against. To evaluate against a whole document, use the document.documentElement.
resolver
A name space resolver created by createNSResolver(), or a user defined name space resolver. Read more on Implementing a User Defined Namespace Resolver if you wish to take the latter approach.
type
A number that corresponds to one of the type constants of nsIXPathResult.
result
An existing nsIXPathResult to use for the result. Using null will create a new nsIXPathResult.
Return value

An XPath result.

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:123 次

字数:7015

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文