本文整理汇总了Java中net.sf.saxon.xpath.XPathEvaluator.setXPathVariableResolver方法的典型用法代码示例。如果您正苦于以下问题:Java XPathEvaluator.setXPathVariableResolver方法的具体用法?Java XPathEvaluator.setXPathVariableResolver怎么用?Java XPathEvaluator.setXPathVariableResolver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.saxon.xpath.XPathEvaluator
的用法示例。
在下文中一共展示了XPathEvaluator.setXPathVariableResolver方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getXPathEvaluator
import net.sf.saxon.xpath.XPathEvaluator; //导入方法依赖的package包/类
/**
* Get a Saxon XPathEvaluator for the purposes of compiling an XPath.
*
* @param pBackwardsCompatible If true, turns XPath 1.0 backwards compatibility mode on.
* @param pNamespaceMap Optional NamespaceContext for resolution of arbitrary namespaces. Leave null to use default.
* @return A new single-use XPathEvaluator.
*/
public static XPathEvaluator getXPathEvaluator(boolean pBackwardsCompatible, DynamicNamespaceContext pNamespaceMap) {
XPathEvaluator lXPE = new XPathEvaluator(SaxonEnvironment.getSaxonConfiguration());
lXPE.getStaticContext().setBackwardsCompatibilityMode(pBackwardsCompatible);
//All XPath expressions should use the ThreadLocal variable resolver if one exists - setup the proxy for accessing it here
lXPE.setXPathVariableResolver(VariableResolverProxy.INSTANCE);
if (pNamespaceMap == null) {
lXPE.setNamespaceContext(gFoxNamespaceContext);
}
else {
lXPE.setNamespaceContext(pNamespaceMap);
}
return lXPE;
}
示例2: evaluate
import net.sf.saxon.xpath.XPathEvaluator; //导入方法依赖的package包/类
@Override
public List<Object> evaluate(TestCase testCase, String file) throws Exception{
XPathFactoryImpl xpf = new XPathFactoryImpl();
XPathEvaluator xpe = (XPathEvaluator)xpf.newXPath();
xpe.getConfiguration().setVersionWarning(false);
((StandardErrorListener)xpe.getConfiguration().getErrorListener()).setRecoveryPolicy(Configuration.RECOVER_SILENTLY);
xpe.getStaticContext().setBackwardsCompatibilityMode(true);
xpe.setXPathVariableResolver(testCase.variableResolver);
xpe.setXPathFunctionResolver(testCase.functionResolver);
xpe.setNamespaceContext(testCase.nsContext);
NodeInfo doc = xpe.getConfiguration().buildDocument(new SAXSource(new InputSource(file)));
List<Object> results = new ArrayList<Object>(testCase.xpaths.size());
for(XPathInfo xpathInfo: testCase.xpaths){
if(xpathInfo.forEach==null)
results.add(xpe.evaluate(xpathInfo.xpath, doc, xpathInfo.resultType));
else{
List<Object> list = new ArrayList<Object>();
List nodeList = (List)xpe.evaluate(xpathInfo.forEach, doc, XPathConstants.NODESET);
for(Object context: nodeList)
list.add(xpe.evaluate(xpathInfo.xpath, context, xpathInfo.resultType));
results.add(list);
}
}
return results;
}