下面列出了怎么用org.w3c.dom.xpath.XPathEvaluator的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Take the received string, which is an XML query expression,
* compile it, and store the compiled query locally. Note
* that for now, we only support XPath because that's what
* Xalan supports.
*
* @param queryExpr The XPath expression to compile
*/
public void compileXQExpr(String queryExpr, String opName)
throws StandardException
{
try {
/* The following XPath constructor compiles the expression
* as part of the construction process. We pass a null
* namespace resolver object so that the implementation will
* provide one for us, which means prefixes will not be resolved
* in the query (Xalan will just throw an error if a prefix
* is used). In the future we may want to revisit this
* to make it easier for users to query based on namespaces.
*/
XPathEvaluator eval = (XPathEvaluator)
dBuilder.getDOMImplementation().getFeature("+XPath", "3.0");
query = eval.createExpression(queryExpr, null);
this.queryExpr = queryExpr;
this.opName = opName;
this.recompileQuery = false;
} catch (Throwable te) {
/* Something went wrong during compilation of the
* expression; wrap the error and re-throw it.
* Note: we catch "Throwable" here to catch as many
* Xalan-produced errors as possible in order to
* minimize the chance of an uncaught Xalan error
* (such as a NullPointerException) causing Derby
* to fail in a more serious way. In particular, an
* uncaught Java exception like NPE can result in
* Derby throwing "ERROR 40XT0: An internal error was
* identified by RawStore module" for all statements on
* the connection after the failure--which we clearly
* don't want. If we catch the error and wrap it,
* though, the statement will fail but Derby will
* continue to run as normal.
*/
throw StandardException.newException(
SQLState.LANG_XML_QUERY_ERROR, te, opName, te.getMessage());
}
}