2
* Copyright (c) 2002 World Wide Web Consortium,
3
* (Massachusetts Institute of Technology, Institut National de
4
* Recherche en Informatique et en Automatique, Keio University). All
5
* Rights Reserved. This program is distributed under the W3C's Software
6
* Intellectual Property License. This program is distributed in the
7
* hope that it will be useful, but WITHOUT ANY WARRANTY; without even
8
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10
* See W3C License http://www.w3.org/Consortium/Legal/ for more details.
13
package org.w3c.dom.xpath;
15
import org.w3c.dom.Node;
16
import org.w3c.dom.DOMException;
19
* <strong>DOM Level 3 WD Experimental:
20
* The DOM Level 3 specification is at the stage
21
* of Working Draft, which represents work in
22
* progress and thus may be updated, replaced,
23
* or obsoleted by other documents at any time.</strong> <p>
24
* <code>XPathEvaluator</code>, which will provide evaluation of XPath 1.0
25
* expressions with no specialized extension functions or variables. It is
26
* expected that the <code>XPathEvaluator</code> interface will be
27
* implemented on the same object which implements the <code>Document</code>
28
* interface in an implementation which supports the XPath DOM module.
29
* <code>XPathEvaluator</code> implementations may be available from other
30
* sources that may provide support for special extension functions or
31
* variables which are not defined in this specification. The methods of
32
* XPathExpression should be named with more-XPath- specific names because
33
* the interface will often be implemented by the same object which
34
* implements document.No change.The point of interfaces is to localize the
35
* implementing namespace. This would make the method names unnecessarily
36
* long and complex even though there are no conflicts in the interface
37
* itself. The new core method getInterface is designed for discovering
38
* interfaces of additional modules that may not be directly implemented on
39
* the objects to which they are attached. This could be used to implement
40
* XPath on a separate object. The user only refers to the separate
41
* interfaces and not the proprietary aggregate implementation.Should entity
42
* refs be supported so that queries can be made on them?No change.We will
43
* not do this now. They are not part of the XPath data model. Note that
44
* they may be present in the hierarchy of returned nodes, but may not
45
* directly be requested or returned in the node set.What does createResult
46
* create when one wants to reuse the XPath?It is not useful.Removed method.
47
* Should ordering be a separate flag, or a type of result that can be
48
* requested. As a type of result, it can be better optimized in
49
* implementations.It makes sense as a type of result. Changed.Removed
50
* method.Implementing XPathEvaluator on Document can be a problem due to
51
* conflicts in the names of the methods.The working group finds no better
52
* solution. GetInterface in Level 3 permits the object to be implemented
53
* separately. We should be committed to this. We will leave this issue open
54
* to see if we get more feedback on it.How does this interface adapt to
55
* XPath 2.0 and other query languages.No change.This interface is not
56
* intended to adapt to XPath 2.0 or other languages. The models of these
57
* are likely to be incompatible enough to require new APIs.For alternate
58
* implementations that can use this API, it can be obtained from different
59
* sources.Support for custom variables and functions would be very useful.
60
* No change.It is possible for an implementation to supply alternative
61
* sources of an XPathEvaluator that can be customized with a custom
62
* variable and function context. We do not specify how this is
63
* accomplished. It is too complex to address in this version of the XPath
65
* <p>See also the <a href='http://www.w3.org/TR/2002/WD-DOM-Level-3-XPath-20020328'>Document Object Model (DOM) Level 3 XPath Specification</a>.
67
public interface XPathEvaluator {
69
* Creates a parsed XPath expression with resolved namespaces. This is
70
* useful when an expression will be reused in an application since it
71
* makes it possible to compile the expression string into a more
72
* efficient internal form and preresolve all namespace prefixes which
73
* occur within the expression.createExpression should not raise
74
* exceptions about type coercion.This was already fixed in the public
76
* @param expression The XPath expression string to be parsed.
77
* @param resolver The <code>resolver</code> permits translation of
78
* prefixes within the XPath expression into appropriate namespace URIs
79
* . If this is specified as <code>null</code>, any namespace prefix
80
* within the expression will result in <code>DOMException</code>
81
* being thrown with the code <code>NAMESPACE_ERR</code>.
82
* @return The compiled form of the XPath expression.
83
* @exception XPathException
84
* INVALID_EXPRESSION_ERR: Raised if the expression is not legal
85
* according to the rules of the <code>XPathEvaluator</code>i
86
* @exception DOMException
87
* NAMESPACE_ERR: Raised if the expression contains namespace prefixes
88
* which cannot be resolved by the specified
89
* <code>XPathNSResolver</code>.
91
public XPathExpression createExpression(String expression,
92
XPathNSResolver resolver)
93
throws XPathException, DOMException;
96
* Adapts any DOM node to resolve namespaces so that an XPath expression
97
* can be easily evaluated relative to the context of the node where it
98
* appeared within the document. This adapter works by calling the
99
* method <code>lookupNamespacePrefix</code> on <code>Node</code>.It
100
* should be possible to create an XPathNSResolver that does not rely on
101
* a node, but which implements a map of resolutions that can be added
102
* to by the application.No change.The application can easily create
103
* this, which was why the interface was designed as it is. The
104
* specification will not require a specific factory at this time for
105
* application populated maps.There should be type restrictions on which
106
* types of nodes may be adapted by createNSResolver.No change.The
107
* namespace methods on the Node interface of the Level 3 core may be
108
* called without exception on all node types. In some cases no non-null
109
* namespace resolution will ever be returned. That is what may also be
110
* expected of this adapter.
111
* @param nodeResolver The node to be used as a context for namespace
113
* @return <code>XPathNSResolver</code> which resolves namespaces with
114
* respect to the definitions in scope for a specified node.
116
public XPathNSResolver createNSResolver(Node nodeResolver);
119
* Evaluates an XPath expression string and returns a result of the
120
* specified type if possible.An exception needs to be raised when an
121
* XPath expression is evaluated on a node such as an EntityReference
122
* which cannot serve as an XPath context node.Done: NOT_SUPPORTED_ERR.A
123
* description is needed of what happens when the node passed to the
124
* evaluation function is a Text or CDATASection in the DOM case where
125
* the text may be fragmented between text nodes.Done.Eliminate the
126
* evaluate method from XPathEvaluator, forcing everyone to create
127
* expressions.No change.Any implementor can easily implement it by
128
* creating an expression. Having it available as a separate routine is
129
* a convenience and may be an optimization as well in some cases.Revert
130
* to multiple evaluateAs methods instead of passing a type code.No
131
* change.This is an alternative which eliminates a method argument
132
* while adding methods, but the type code is used to designate the type
133
* on returns anyway and using it as an argument to specify any coercion
134
* seems natural to many.Error exceptions are needed when there is a
135
* mismatch between the implementation of XPathEvaluator and the context
136
* node being evaluated.Done: WRONG_DOCUMENT_ERRConcern that the XPath
137
* API should only support natural results of XPath expression, without
138
* convenience coercion or alternative representations. Any special
139
* thing such as ordering should be added later to resultNo change.We
140
* have significant use cases for returning alternative types and
141
* representations by explicit request in advance.Eliminate the reusable
142
* result argument.No change.No. We have use cases for it, and there is
143
* already an implementation showing there is nothing wrong with it.
144
* State that the XPathNSResolver argument may be a function in
145
* Javascript.Yes.There is an exception when there is a problem parsing
146
* the expression, but none when there is a problem evaluating the
147
* expression.No change.If the expression parsing was OK, then the worst
148
* that can happen is an empty result is returned.When requesting any
149
* type, the implementation should be permitted to return any type of
150
* node set, i.e. ordered or unordered, it finds convenient.No change.
151
* The iterator it returns may contain ordered results, but identifying
152
* it as such produces undesirable results, because it would create
153
* complexity for the user -- requiring checking two types to see if the
154
* result was a node set -- or incompatibility caused by assuming it was
155
* always the one returned by a particular implementation the developer
156
* was using.NAMESPACE_ERR description is not appropriate to the way it
157
* is being used here.Make the description of NAMESPACE_ERR in the core
158
* specification more general.Should the INVALID_EXPRESSION_ERR be
159
* INVALID_SYNTAX_ERR?No change.We can improve the description of the
160
* error, but the name is appropriate as-is. It covers not only syntax
161
* errors but expression errors, such as when the implementation has no
162
* custom functions or variables but the expression specifies custom
163
* functions or variables.
164
* @param expression The XPath expression string to be parsed and
166
* @param contextNode The <code>context</code> is context node for the
167
* evaluation of this XPath expression. If the XPathEvaluator was
168
* obtained by casting the <code>Document</code> then this must be
169
* owned by the same document and must be a <code>Document</code>,
170
* <code>Element</code>, <code>Attribute</code>, <code>Text</code>,
171
* <code>CDATASection</code>, <code>Comment</code>,
172
* <code>ProcessingInstruction</code>, or <code>XPathNamespace</code>
173
* node. If the context node is a <code>Text</code> or a
174
* <code>CDATASection</code>, then the context is interpreted as the
175
* whole logical text node as seen by XPath, unless the node is empty
176
* in which case it may not serve as the XPath context.
177
* @param resolver The <code>resolver</code> permits translation of
178
* prefixes within the XPath expression into appropriate namespace URIs
179
* . If this is specified as <code>null</code>, any namespace prefix
180
* within the expression will result in <code>DOMException</code>
181
* being thrown with the code <code>NAMESPACE_ERR</code>.
182
* @param type If a specific <code>type</code> is specified, then the
183
* result will be coerced to return the specified type relying on
184
* XPath type conversions and fail if the desired coercion is not
185
* possible. This must be one of the type codes of
186
* <code>XPathResult</code>.
187
* @param result The <code>result</code> specifies a specific
188
* <code>XPathResult</code> which may be reused and returned by this
189
* method. If this is specified as <code>null</code>or the
190
* implementation cannot reuse the specified result, a new
191
* <code>XPathResult</code> will be constructed and returned.
192
* @return The result of the evaluation of the XPath expression.
193
* @exception XPathException
194
* INVALID_EXPRESSION_ERR: Raised if the expression is not legal
195
* according to the rules of the <code>XPathEvaluator</code>i
196
* <br>TYPE_ERR: Raised if the result cannot be converted to return the
198
* @exception DOMException
199
* NAMESPACE_ERR: Raised if the expression contains namespace prefixes
200
* which cannot be resolved by the specified
201
* <code>XPathNSResolver</code>.
202
* <br>WRONG_DOCUMENT_ERR: The Node is from a document that is not
203
* supported by this XPathEvaluator.
204
* <br>NOT_SUPPORTED_ERR: The Node is not a type permitted as an XPath
207
public Object evaluate(String expression,
209
XPathNSResolver resolver,
212
throws XPathException, DOMException;