Search in sources :

Example 1 with XPathCompiler

use of net.sf.saxon.s9api.XPathCompiler in project sirix by sirixdb.

the class XPathEvaluator method call.

@Override
public XPathSelector call() throws Exception {
    final Processor proc = new Processor(false);
    final Configuration config = proc.getUnderlyingConfiguration();
    final NodeInfo doc = new DocumentWrapper(mSession, mRevision, config);
    final XPathCompiler xpath = proc.newXPathCompiler();
    final DocumentBuilder builder = proc.newDocumentBuilder();
    final XdmItem item = builder.wrap(doc);
    final XPathSelector selector = xpath.compile(mExpression).load();
    selector.setContextItem(item);
    return selector;
}
Also used : DocumentWrapper(org.sirix.saxon.wrapper.DocumentWrapper) Processor(net.sf.saxon.s9api.Processor) Configuration(net.sf.saxon.Configuration) XPathCompiler(net.sf.saxon.s9api.XPathCompiler) DocumentBuilder(net.sf.saxon.s9api.DocumentBuilder) NodeInfo(net.sf.saxon.om.NodeInfo) XPathSelector(net.sf.saxon.s9api.XPathSelector) XdmItem(net.sf.saxon.s9api.XdmItem)

Example 2 with XPathCompiler

use of net.sf.saxon.s9api.XPathCompiler in project jmeter by apache.

the class XPathUtilTest method testBug63033.

@Test
public void testBug63033() throws SaxonApiException {
    Processor p = new Processor(false);
    XPathCompiler c = p.newXPathCompiler();
    c.declareNamespace("age", "http://www.w3.org/2003/01/geo/wgs84_pos#");
    String xPathQuery = "//Employees/Employee[1]/age:ag";
    XPathExecutable e = c.compile(xPathQuery);
    XPathSelector selector = e.load();
    selector.setContextItem(p.newDocumentBuilder().build(new StreamSource(new StringReader(xmlDoc))));
    XdmValue nodes = selector.evaluate();
    XdmItem item = nodes.itemAt(0);
    assertEquals("<age:ag xmlns:age=\"http://www.w3.org/2003/01/geo/wgs84_pos#\">29</age:ag>", item.toString());
}
Also used : XdmValue(net.sf.saxon.s9api.XdmValue) Processor(net.sf.saxon.s9api.Processor) XPathCompiler(net.sf.saxon.s9api.XPathCompiler) XPathSelector(net.sf.saxon.s9api.XPathSelector) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) XPathExecutable(net.sf.saxon.s9api.XPathExecutable) XdmItem(net.sf.saxon.s9api.XdmItem) Test(org.junit.jupiter.api.Test)

Example 3 with XPathCompiler

use of net.sf.saxon.s9api.XPathCompiler in project jmeter by apache.

the class XPathQueryCacheLoader method load.

@Override
public XPathExecutable load(ImmutablePair<String, String> key) throws Exception {
    String xPathQuery = key.left;
    String namespacesString = key.right;
    Processor processor = XPathUtil.getProcessor();
    XPathCompiler xPathCompiler = processor.newXPathCompiler();
    List<String[]> namespacesList = XPathUtil.namespacesParse(namespacesString);
    log.debug("Parsed namespaces:{} into list of namespaces:{}", namespacesString, namespacesList);
    for (String[] namespaces : namespacesList) {
        xPathCompiler.declareNamespace(namespaces[0], namespaces[1]);
    }
    log.debug("Declared namespaces:{}, now compiling xPathQuery:{}", namespacesList, xPathQuery);
    return xPathCompiler.compile(xPathQuery);
}
Also used : Processor(net.sf.saxon.s9api.Processor) XPathCompiler(net.sf.saxon.s9api.XPathCompiler)

Aggregations

Processor (net.sf.saxon.s9api.Processor)3 XPathCompiler (net.sf.saxon.s9api.XPathCompiler)3 XPathSelector (net.sf.saxon.s9api.XPathSelector)2 XdmItem (net.sf.saxon.s9api.XdmItem)2 StringReader (java.io.StringReader)1 StreamSource (javax.xml.transform.stream.StreamSource)1 Configuration (net.sf.saxon.Configuration)1 NodeInfo (net.sf.saxon.om.NodeInfo)1 DocumentBuilder (net.sf.saxon.s9api.DocumentBuilder)1 XPathExecutable (net.sf.saxon.s9api.XPathExecutable)1 XdmValue (net.sf.saxon.s9api.XdmValue)1 Test (org.junit.jupiter.api.Test)1 DocumentWrapper (org.sirix.saxon.wrapper.DocumentWrapper)1