• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java XPathEvaluator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中net.sf.saxon.xpath.XPathEvaluator的典型用法代码示例。如果您正苦于以下问题:Java XPathEvaluator类的具体用法?Java XPathEvaluator怎么用?Java XPathEvaluator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



XPathEvaluator类属于net.sf.saxon.xpath包,在下文中一共展示了XPathEvaluator类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:24,代码来源:SaxonEnvironment.java


示例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;
}
 
开发者ID:santhosh-tekuri,项目名称:jlibs,代码行数:27,代码来源:SaxonEngine.java


示例3: _createXPathContext

import net.sf.saxon.xpath.XPathEvaluator; //导入依赖的package包/类
@Nonnull
private XPath _createXPathContext ()
{
  final MapBasedNamespaceContext aNamespaceContext = getNamespaceContext ();
  final XPath aXPathContext = XPathHelper.createNewXPath (m_aXPathFactory,
                                                          m_aXPathVariableResolver,
                                                          m_aXPathFunctionResolver,
                                                          aNamespaceContext);

  if ("net.sf.saxon.xpath.XPathEvaluator".equals (aXPathContext.getClass ().getName ()))
  {
    // Saxon implementation special handling
    final XPathEvaluator aSaxonXPath = (XPathEvaluator) aXPathContext;

    // Since 9.7.0-4 it must implement NamespaceResolver
    aSaxonXPath.setNamespaceContext (new SaxonNamespaceContext (aNamespaceContext));

    // Wrap the PSErrorHandler to a ErrorListener
    aSaxonXPath.getConfiguration ().setErrorListener (new PSErrorListener (getErrorHandler ()));
  }
  return aXPathContext;
}
 
开发者ID:phax,项目名称:ph-schematron,代码行数:23,代码来源:PSXPathBoundSchema.java


示例4: isContained

import net.sf.saxon.xpath.XPathEvaluator; //导入依赖的package包/类
private boolean isContained(TestAssertion assertion, String fileLocation)
		throws XPathExpressionException,
		XPathFactoryConfigurationException, XPathException {
	XPathFactory xpathFactory = XPathFactory
			.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON);
	XPathEvaluator xpath = (XPathEvaluator) xpathFactory.newXPath();
	xpath.getConfiguration().setLineNumbering(true);
	xpath.setNamespaceContext(new BpelNamespaceContext());
	XPathExpression expr = xpath.compile(assertion.getTarget());
	InputSource inputSource = new InputSource(
			new File(fileLocation).toString());
	SAXSource saxSource = new SAXSource(inputSource);
	NodeInfo doc = xpath.getConfiguration().buildDocument(saxSource);

	@SuppressWarnings("unchecked")
	List<NodeInfo> matchedLines = (List<NodeInfo>) expr.evaluate(doc,
			XPathConstants.NODESET);
	if (matchedLines.size() > 0) {
		return true;
	}

	return false;
}
 
开发者ID:uniba-dsg,项目名称:bpp,代码行数:24,代码来源:TestRunner.java


示例5: setUp

import net.sf.saxon.xpath.XPathEvaluator; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    super.setUp();
    exchange = new DefaultExchange(context);
    evaluator = new XPathEvaluator();
    doc = evaluator.setSource(new StringSource(CONTENT));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:SaxonConverterTest.java


示例6: FoxXPath

import net.sf.saxon.xpath.XPathEvaluator; //导入依赖的package包/类
/**
 * Construct a new FoxXPath for the given XPath string.
 * @param pXPathDefinition XPath definition containing a FOX-compliant executable XPath string, possibly containing :{contexts} and/or custom FOX functions.
 * @param pUseXPathBackwardsCompatibility If true, switches XPath 1.0 backwards compatibility mode on.
 * @param pNamespaceMap Optional map for namespace-aware XPath processing.
 * @throws ExBadPath If the XPath cannot be compiled for any reason.
 */
FoxXPath(XPathDefinition pXPathDefinition, boolean pUseXPathBackwardsCompatibility, DynamicNamespaceContext pNamespaceMap)
throws ExBadPath {

  long lStartTime = System.currentTimeMillis();
  mXPathDefinition = pXPathDefinition;
  mLabelSet = new LinkedHashSet<>();
  mInternalXPathString = SaxonEnvironment.replaceFoxMarkup(pXPathDefinition.getExecutableXPath(), mLabelSet);

  //If there are no labels, clear away the set object as it's no longer needed
  if(mLabelSet.size() == 0){
    mLabelSet = null;
  }

  XPathEvaluator lXPathEvaluator = SaxonEnvironment.getXPathEvaluator(pUseXPathBackwardsCompatibility, pNamespaceMap);

  try {
    //Compile the XPath and store the result of the compilation.
    mXPathExpression = lXPathEvaluator.compile(mInternalXPathString);
  }
  catch (XPathExpressionException e) {
    throw new ExBadPath("Bad XPath for original extended XPath: '" + mXPathDefinition.getPathForDebug() +  "'. " +
      (mXPathDefinition.getExecutableXPath().equals(mInternalXPathString) ? "" : "\nNote: FOX markup in the XPath was rewritten to: '" + mInternalXPathString + "'"), e);
  }

  //Establish dependencies - Saxon gives us a bitmap which we AND against the relevant constants
  int lDeps = ((XPathExpressionImpl) mXPathExpression).getInternalExpression().getDependencies();
  mUsesContextItem = (StaticProperty.DEPENDS_ON_CONTEXT_ITEM & lDeps) > 0;
  mUsesContextDocument = (StaticProperty.DEPENDS_ON_CONTEXT_DOCUMENT & lDeps) > 0;

  //Store the compile time
  mCompileTime = System.currentTimeMillis() - lStartTime;
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:40,代码来源:FoxXPath.java


示例7: evaluate

import net.sf.saxon.xpath.XPathEvaluator; //导入依赖的package包/类
@Override
public List<Object> evaluate(TestCase testCase, String file) throws Exception{
    Document doc = toDOM(file);
    List<Object> results = new ArrayList<Object>(testCase.xpaths.size());
    XPath xpathObj = factory.newXPath();
    if(xpathObj instanceof XPathEvaluator){
        XPathEvaluator xpe = (XPathEvaluator)xpathObj;
        xpe.getConfiguration().setVersionWarning(false);
        ((StandardErrorListener)xpe.getConfiguration().getErrorListener()).setRecoveryPolicy(Configuration.RECOVER_SILENTLY);
        xpe.getStaticContext().setBackwardsCompatibilityMode(true);
    }
    for(XPathInfo xpathInfo: testCase.xpaths){
        xpathObj.setXPathVariableResolver(testCase.variableResolver);
        xpathObj.setXPathFunctionResolver(testCase.functionResolver);
        xpathObj.setNamespaceContext(testCase.nsContext);

        if(xpathInfo.forEach==null)
            results.add(xpathObj.evaluate(xpathInfo.xpath, doc, xpathInfo.resultType));
        else{
            List<Object> list = new ArrayList<Object>();
            NodeList nodeList = (NodeList)xpathObj.evaluate(xpathInfo.forEach, doc, XPathConstants.NODESET);
            for(int i=0; i<nodeList.getLength(); i++){
                Object context = nodeList.item(i);
                list.add(xpathObj.evaluate(xpathInfo.xpath, context, xpathInfo.resultType));
            }
            results.add(list);
        }
    }
    return results;
}
 
开发者ID:santhosh-tekuri,项目名称:jlibs,代码行数:31,代码来源:JDKEngine.java


示例8: createXPathEvaluator

import net.sf.saxon.xpath.XPathEvaluator; //导入依赖的package包/类
private void createXPathEvaluator()
		throws XPathFactoryConfigurationException {
	XPathFactory xpathFactory = XPathFactory
			.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON);
	xpath = (XPathEvaluator) xpathFactory.newXPath();
	xpath.getConfiguration().setLineNumbering(true);
	xpath.setNamespaceContext(new BpmnNamespaceContext());
}
 
开发者ID:uniba-dsg,项目名称:prope,代码行数:9,代码来源:XPathNodeCounter.java


示例9: isContained

import net.sf.saxon.xpath.XPathEvaluator; //导入依赖的package包/类
private boolean isContained(AdaptableElement element, String fileLocation) {
	try {
		XPathFactory xpathFactory = XPathFactory
				.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON);
		XPathEvaluator xpath = (XPathEvaluator) xpathFactory.newXPath();
		xpath.getConfiguration().setLineNumbering(true);
		xpath.setNamespaceContext(new BpmnNamespaceContext());
		XPathExpression expr = xpath
				.compile(element.getLocatorExpression());
		InputSource inputSource = new InputSource(
				new File(fileLocation).toString());
		SAXSource saxSource = new SAXSource(inputSource);
		NodeInfo doc = xpath.getConfiguration().buildDocument(saxSource);;

		@SuppressWarnings("unchecked")
		List<NodeInfo> matchedLines = (List<NodeInfo>) expr.evaluate(doc,
				XPathConstants.NODESET);
		if (matchedLines.size() > 0) {
			return true;
		}

		return false;
	} catch (XPathFactoryConfigurationException | XPathExpressionException
			| XPathException e) {
		e.printStackTrace();
		return false;
	}
}
 
开发者ID:uniba-dsg,项目名称:prope,代码行数:29,代码来源:ElementXPathTests.java


示例10: createXPathEvaluator

import net.sf.saxon.xpath.XPathEvaluator; //导入依赖的package包/类
private void createXPathEvaluator()
		throws XPathFactoryConfigurationException {
	XPathFactory xpathFactory = XPathFactory
			.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON);
	xpath = (XPathEvaluator) xpathFactory.newXPath();
	xpath.getConfiguration().setLineNumbering(true);
	xpath.setNamespaceContext(new BpelNamespaceContext());
}
 
开发者ID:lenhard,项目名称:pete,代码行数:9,代码来源:XPathNodeCounter.java


示例11: isContained

import net.sf.saxon.xpath.XPathEvaluator; //导入依赖的package包/类
private boolean isContained(AdaptableElement element, String fileLocation) {
	try {
		XPathFactory xpathFactory = XPathFactory
				.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON);
		XPathEvaluator xpath = (XPathEvaluator) xpathFactory.newXPath();
		xpath.getConfiguration().setLineNumbering(true);
		xpath.setNamespaceContext(new BpmnNamespaceContext());
		XPathExpression expr = xpath
				.compile(element.getLocatorExpression());
		InputSource inputSource = new InputSource(
				new File(fileLocation).toString());
		SAXSource saxSource = new SAXSource(inputSource);
		NodeInfo doc = xpath.setSource(saxSource);

		@SuppressWarnings("unchecked")
		List<NodeInfo> matchedLines = (List<NodeInfo>) expr.evaluate(doc,
				XPathConstants.NODESET);
		if (matchedLines.size() > 0) {
			return true;
		}

		return false;
	} catch (XPathFactoryConfigurationException | XPathExpressionException
			| XPathException e) {
		e.printStackTrace();
		return false;
	}
}
 
开发者ID:lenhard,项目名称:pete,代码行数:29,代码来源:ElementXPathTests.java


示例12: init

import net.sf.saxon.xpath.XPathEvaluator; //导入依赖的package包/类
private void init() throws XPathExpressionException {
    XPathEvaluator xPathEvaluator = new XPathEvaluator();
    xPathEvaluator.setNamespaceContext(XPath2NamespaceContext.INSTANCE);
    xPathExpression = xPathEvaluator.compile(xpathStr);
}
 
开发者ID:yuany,项目名称:en-webmagic,代码行数:6,代码来源:Xpath2Selector.java



注:本文中的net.sf.saxon.xpath.XPathEvaluator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SingleStreamCodeWriter类代码示例发布时间:2022-05-22
下一篇:
Java AdventureSettings类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap