本文整理汇总了Java中net.sf.saxon.xpath.XPathEvaluator.setNamespaceContext方法的典型用法代码示例。如果您正苦于以下问题:Java XPathEvaluator.setNamespaceContext方法的具体用法?Java XPathEvaluator.setNamespaceContext怎么用?Java XPathEvaluator.setNamespaceContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.saxon.xpath.XPathEvaluator
的用法示例。
在下文中一共展示了XPathEvaluator.setNamespaceContext方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
示例5: 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());
}
示例6: 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;
}
}
示例7: 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());
}
示例8: 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;
}
}
示例9: 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);
}