本文整理汇总了Java中net.sf.saxon.s9api.XPathSelector类的典型用法代码示例。如果您正苦于以下问题:Java XPathSelector类的具体用法?Java XPathSelector怎么用?Java XPathSelector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XPathSelector类属于net.sf.saxon.s9api包,在下文中一共展示了XPathSelector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getExpressionEvaluatorFactory
import net.sf.saxon.s9api.XPathSelector; //导入依赖的package包/类
@Override
public ExpressionEvaluatorFactory<XdmItem> getExpressionEvaluatorFactory() {
return entry -> expression -> {
try {
XPathSelector selector = xpath.compile(expression).load();
selector.setContextItem(entry);
XdmItem value = selector.evaluateSingle();
if (value == null) {
return Optional.empty();
}
String result = autoNodeTextExtraction ? value.getStringValue() : value.toString();
return Optional.of(result);
} catch (SaxonApiException e) {
throw new RuntimeException(String.format(
"Error applying XPath expression [%s] to entry [%s]", entry, expression),
e);
}
};
}
开发者ID:carml,项目名称:carml,代码行数:23,代码来源:XPathResolver.java
示例2: testAddAttribute
import net.sf.saxon.s9api.XPathSelector; //导入依赖的package包/类
@Test
public void testAddAttribute() throws Exception {
GauloisPipe piper = new GauloisPipe(configFactory);
ConfigUtil cu = new ConfigUtil(configFactory.getConfiguration(), piper.getUriResolver(), "./src/test/resources/AddAttributeJavaStep.xml");
Config config = cu.buildConfig(emptyInputParams);
config.verify();
piper.setConfig(config);
piper.setInstanceName("ADD_ATTRIBUTE");
piper.launch();
Processor proc = new Processor(configFactory.getConfiguration());
File expect = new File("target/generated-test-files/source-identity-addAttribute.xml");
XdmNode document = proc.newDocumentBuilder().build(expect);
XPathExecutable exec = proc.newXPathCompiler().compile("//*[@test]");
XPathSelector selector = exec.load();
selector.setContextItem((XdmItem)document);
XdmValue result = selector.evaluate();
assertTrue(result.size()>0);
expect.delete();
}
开发者ID:cmarchand,项目名称:gaulois-pipe,代码行数:20,代码来源:GauloisPipeTest.java
示例3: testXdmValueToXsl
import net.sf.saxon.s9api.XPathSelector; //导入依赖的package包/类
@Test
public void testXdmValueToXsl() throws InvalidSyntaxException, SaxonApiException, URISyntaxException, IOException, ValidationException {
GauloisPipe piper = new GauloisPipe(configFactory);
ConfigUtil cu = new ConfigUtil(configFactory.getConfiguration(), piper.getUriResolver(), "./src/test/resources/paramDate.xml");
HashMap<QName,ParameterValue> params = new HashMap<>();
QName qnDate = new QName("date");
// to get a date XdmValue from saxon, we must be brilliants !
Processor proc = new Processor(configFactory.getConfiguration());
XQueryEvaluator ev = proc.newXQueryCompiler().compile("current-dateTime()").load();
XdmItem item = ev.evaluateSingle();
params.put(qnDate, new ParameterValue(qnDate, item, factory.getDatatype(new QName("xs","http://www.w3.org/2001/XMLSchema","dateTime"))));
Config config = cu.buildConfig(params);
config.verify();
piper.setConfig(config);
piper.setInstanceName("XDM_VALUE_TO_XSL");
piper.launch();
File expect = new File("target/generated-test-files/date-output.xml");
XdmNode document = proc.newDocumentBuilder().build(expect);
XPathExecutable exec = proc.newXPathCompiler().compile("/date");
XPathSelector selector = exec.load();
selector.setContextItem((XdmItem)document);
XdmValue result = selector.evaluate();
assertTrue(result.size()>0);
}
开发者ID:cmarchand,项目名称:gaulois-pipe,代码行数:25,代码来源:GauloisPipeTest.java
示例4: testStaticBaseUri
import net.sf.saxon.s9api.XPathSelector; //导入依赖的package包/类
public void testStaticBaseUri() throws InvalidSyntaxException, SaxonApiException, URISyntaxException, IOException, ValidationException {
File expect = new File("target/generated-test-file/static-base-uri-ret.xml");
if(expect.exists()) expect.delete();
GauloisPipe piper = new GauloisPipe(configFactory);
ConfigUtil cu = new ConfigUtil(configFactory.getConfiguration(), piper.getUriResolver(), "./src/test/resources/static-base-uri.xml");
HashMap<QName,ParameterValue> params = new HashMap<>();
Config config = cu.buildConfig(params);
config.verify();
piper.setConfig(config);
piper.setInstanceName("STATIC-BASE-URI");
piper.launch();
assertTrue(expect.exists());
Processor proc = new Processor(configFactory.getConfiguration());
XdmNode document = proc.newDocumentBuilder().build(expect);
XPathExecutable exec = proc.newXPathCompiler().compile("/ret/*/text()");
XPathSelector selector = exec.load();
selector.setContextItem((XdmItem)document);
XdmValue result = selector.evaluate();
String staticBaseUri = result.itemAt(0).getStringValue();
String gpStaticBaseUri = result.itemAt(1).getStringValue();
assertTrue("gp:staticBaseUri does not ends with target/classes/xsl/static-base-uri-ret.xml", gpStaticBaseUri.endsWith("target/classes/xsl/static-base-uri-ret.xml"));
expect.delete();
}
开发者ID:cmarchand,项目名称:gaulois-pipe,代码行数:24,代码来源:GauloisPipeTest.java
示例5: checkResult
import net.sf.saxon.s9api.XPathSelector; //导入依赖的package包/类
private void checkResult(final XsltConref xsltConref, final NodeInfo resolvedElement) {
// check for missing class attribute
try {
final XdmNode context = new XdmNode(resolvedElement);
final XPathSelector sel = otResolver.getXPathCache().getXPathSelector(MISSING_CLASS_XPATH, context);
final XdmItem item = sel.evaluateSingle();
if (item != null) {
String name;
if (item instanceof XdmNode) {
name = "node '" + ((XdmNode)item).getNodeName() + "'";
} else {
name = "item '" + item.getStringValue() + "'";
}
otResolver.getOtLogger().error("[DOT-DITA-SEMIA][ERROR] Missing class attribute in resolved xslt-conref '" + xsltConref.getScriptName() + "'. E.g. on " + name + ".");
}
} catch (SaxonApiException | XPathException e) {
logger.error(e.getMessage(), e);
}
}
开发者ID:dita-semia,项目名称:dita-semia-resolver,代码行数:24,代码来源:ResolveXsltConrefCall.java
示例6: applyXpath
import net.sf.saxon.s9api.XPathSelector; //导入依赖的package包/类
public static List<String> applyXpath(String xml, String xpathString) {
List<String> result = new ArrayList<>();
try {
Processor proc = new Processor(false);
XPathCompiler xpath = proc.newXPathCompiler();
DocumentBuilder builder = proc.newDocumentBuilder();
// Load the XML document.
StringReader reader = new StringReader(xml);
XdmNode doc = builder.build(new StreamSource(reader));
// Compile the xpath
XPathSelector selector = xpath.compile(xpathString).load();
selector.setContextItem(doc);
// Evaluate the expression.
XdmValue nodes = selector.evaluate();
for (XdmItem item : nodes) {
result.add(item.toString());
}
} catch (Exception e) {
LOGGER.error("Error applying XPath", e);
}
return result;
}
开发者ID:keeps,项目名称:roda-in,代码行数:28,代码来源:TemplateUtils.java
示例7: evaluateXPath2
import net.sf.saxon.s9api.XPathSelector; //导入依赖的package包/类
/**
* Evaluates an XPath 2.0 expression using the Saxon s9api interfaces.
*
* @param xmlSource
* The XML Source.
* @param expr
* The XPath expression to be evaluated.
* @param nsBindings
* A collection of namespace bindings required to evaluate the
* XPath expression, where each entry maps a namespace URI (key)
* to a prefix (value).
* @return An XdmValue object representing a value in the XDM data model;
* this is a sequence of zero or more items, where each item is
* either an atomic value or a node.
* @throws SaxonApiException
* If an error occurs while evaluating the expression; this
* always wraps some other underlying exception.
*/
public static XdmValue evaluateXPath2(Source xmlSource, String expr,
Map<String, String> nsBindings) throws SaxonApiException {
Processor proc = new Processor(false);
XPathCompiler compiler = proc.newXPathCompiler();
for (String nsURI : nsBindings.keySet()) {
compiler.declareNamespace(nsBindings.get(nsURI), nsURI);
}
XPathSelector xpath = compiler.compile(expr).load();
DocumentBuilder builder = proc.newDocumentBuilder();
XdmNode node = null;
if (DOMSource.class.isInstance(xmlSource)) {
DOMSource domSource = (DOMSource) xmlSource;
node = builder.wrap(domSource.getNode());
} else {
node = builder.build(xmlSource);
}
xpath.setContextItem(node);
return xpath.evaluate();
}
开发者ID:opengeospatial,项目名称:ets-osxgeotime10,代码行数:38,代码来源:XMLUtils.java
示例8: getIterableXpathResult
import net.sf.saxon.s9api.XPathSelector; //导入依赖的package包/类
private Iterable<XdmItem> getIterableXpathResult(String source, String iteratorExpression) {
DocumentBuilder documentBuilder = xpathProcessor.newDocumentBuilder();
StringReader reader = new StringReader(source);
try {
XdmNode item = documentBuilder.build(new StreamSource(reader));
XPathSelector selector = xpath.compile(iteratorExpression).load();
selector.setContextItem(item);
return selector;
} catch (SaxonApiException e) {
throw new RuntimeException(e);
}
}
开发者ID:carml,项目名称:carml,代码行数:13,代码来源:XPathResolver.java
示例9: initialize
import net.sf.saxon.s9api.XPathSelector; //导入依赖的package包/类
@Override
public void initialize(InputSplit inSplit, TaskAttemptContext context)
throws IOException, InterruptedException {
Path file = ((FileSplit)inSplit).getPath();
FileSystem fs = file.getFileSystem(context.getConfiguration());
FSDataInputStream fileIn = fs.open(file);
DocumentBuilder docBuilder = builderLocal.get();
try {
Document document = docBuilder.parse(fileIn);
net.sf.saxon.s9api.DocumentBuilder db = saxonBuilderLocal.get();
XdmNode xdmDoc = db.wrap(document);
XPathCompiler xpath = proc.newXPathCompiler();
xpath.declareNamespace("wp",
"http://www.mediawiki.org/xml/export-0.4/");
XPathSelector selector = xpath.compile(PATH_EXPRESSION).load();
selector.setContextItem(xdmDoc);
items = new ArrayList<XdmItem>();
for (XdmItem item : selector) {
items.add(item);
}
} catch (SAXException ex) {
ex.printStackTrace();
throw new IOException(ex);
} catch (SaxonApiException e) {
e.printStackTrace();
} finally {
if (fileIn != null) {
fileIn.close();
}
}
}
开发者ID:marklogic,项目名称:marklogic-contentpump,代码行数:32,代码来源:LinkCountHDFS.java
示例10: evaluate
import net.sf.saxon.s9api.XPathSelector; //导入依赖的package包/类
/**
* This evaluates an XML message against a provided XPath expression.
*
* @param inputStream input stream to be evaluated
* @param xpathExpression XPath expression to evaluate the OMElement against
* @return The resulting value
* @throws MessageBodyEvaluationException
*/
@Override
public Object evaluate(InputStream inputStream, String xpathExpression) throws MessageBodyEvaluationException {
try {
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
DocumentBuilder builder = processor.newDocumentBuilder();
XdmNode doc = builder.build(new StreamSource(inputStreamReader));
XPathSelector selector = xPathCompiler.compile(xpathExpression).load();
selector.setContextItem(doc);
return selector.evaluate();
} catch (SaxonApiException e) {
throw new MessageBodyEvaluationException("There is a problem evaluating the XPath", e);
}
}
开发者ID:wso2-attic,项目名称:carbon-gateway-framework,代码行数:22,代码来源:XPathEvaluator.java
示例11: constructElementParserDatatype
import net.sf.saxon.s9api.XPathSelector; //导入依赖的package包/类
private Datatype constructElementParserDatatype(final QName qn, final boolean allowsEmpty, final boolean allowsMultiple) throws ValidationException {
return new Datatype() {
@Override
public boolean isAtomic() { return false; }
@Override
public boolean allowsMultiple() { return allowsMultiple; }
@Override
public boolean allowsEmpty() { return allowsEmpty; }
@Override
public XdmValue convert(String input, Configuration configuration) throws ValidationException {
Processor proc = new Processor(configuration);
DocumentBuilder builder = proc.newDocumentBuilder();
String wrappedInput="<fake:document xmlns:fake=\"top:marchand:xml:gaulois:wrapper\">".concat(input).concat("</fake:document>");
InputStream is = new ByteArrayInputStream(wrappedInput.getBytes(Charset.forName("UTF-8")));
try {
XdmNode documentNode = builder.build(new StreamSource(is));
XPathCompiler compiler = proc.newXPathCompiler();
compiler.declareNamespace("fake", "top:marchand:xml:gaulois:wrapper");
XPathSelector selector = compiler.compile("/fake:document/node()").load();
selector.setContextItem(documentNode);
XdmValue ret = selector.evaluate();
if(ret.size()==0 && !allowsEmpty()) throw new ValidationException(qn.toString()+" does not allow empty sequence");
if(ret.size()>1 && !allowsMultiple()) throw new ValidationException(qn.toString()+" does not allow sequence with more than one element");
return ret;
} catch(SaxonApiException ex) {
throw new ValidationException(input+" can not be casted to "+qn.toString());
}
}
};
}
开发者ID:cmarchand,项目名称:gaulois-pipe,代码行数:31,代码来源:DatatypeFactory.java
示例12: getXPathSelector
import net.sf.saxon.s9api.XPathSelector; //导入依赖的package包/类
public XPathSelector getXPathSelector(String xPath, XdmNode context) throws XPathException, SaxonApiException {
final boolean schemaAware = (context.getUnderlyingNode().getSchemaType() != Untyped.getInstance());
final XPathExecutable executable = getXPathExecutable(xPath, schemaAware);
final XPathSelector selector = executable.load();
selector.setContextItem(context);
return selector;
}
开发者ID:dita-semia,项目名称:dita-semia-resolver,代码行数:8,代码来源:XPathCache.java
示例13: getXPathSelector
import net.sf.saxon.s9api.XPathSelector; //导入依赖的package包/类
private XPathSelector getXPathSelector(String xPath) throws XPathException, SaxonApiException {
if (xPathCache == null) {
throw new XPathException("SaxonNodeWrapper: Can't evaluate XPath ('" + xPath + "') without XPathCache.");
} else {
return xPathCache.getXPathSelector(xPath, new XdmNode(saxonNode));
}
}
开发者ID:dita-semia,项目名称:dita-semia-resolver,代码行数:8,代码来源:SaxonNodeWrapper.java
示例14: select
import net.sf.saxon.s9api.XPathSelector; //导入依赖的package包/类
public XPathSelector select(String expr, IndependentContext context, @Nullable XdmItem contextItem) throws SaxonApiException {
XPathSelector xpathSel = this.compile(expr, context).load();
if (contextItem != null) {
xpathSel.setContextItem(contextItem);
}
return xpathSel;
}
开发者ID:esacinc,项目名称:crigtt,代码行数:10,代码来源:CrigttXpathCompiler.java
示例15: evaluate
import net.sf.saxon.s9api.XPathSelector; //导入依赖的package包/类
public static XdmValue evaluate(XPathCompiler compiler, String xpath)
throws ToolsException
, SaxonApiException
{
XPathExecutable exec = compiler.compile(xpath);
XPathSelector expr = exec.load();
return expr.evaluate();
}
开发者ID:fgeorges,项目名称:expath-file-java,代码行数:9,代码来源:SaxonTools.java
注:本文中的net.sf.saxon.s9api.XPathSelector类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论