Search in sources :

Example 6 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project sirix by sirixdb.

the class XQueryEvaluator method call.

@Override
public XdmValue call() throws Exception {
    XdmValue value = null;
    try {
        final Processor proc = new Processor(false);
        final Configuration config = proc.getUnderlyingConfiguration();
        final NodeInfo doc = new DocumentWrapper(mSession, config);
        final XQueryCompiler comp = proc.newXQueryCompiler();
        final XQueryExecutable exp = comp.compile(mExpression);
        final net.sf.saxon.s9api.XQueryEvaluator exe = exp.load();
        exe.setSource(doc);
        value = exe.evaluate();
    } catch (final SaxonApiException e) {
        LOGGER.error("Saxon Exception: " + e.getMessage(), e);
        throw e;
    }
    return value;
}
Also used : XdmValue(net.sf.saxon.s9api.XdmValue) XQueryExecutable(net.sf.saxon.s9api.XQueryExecutable) DocumentWrapper(org.sirix.saxon.wrapper.DocumentWrapper) Processor(net.sf.saxon.s9api.Processor) Configuration(net.sf.saxon.Configuration) NodeInfo(net.sf.saxon.om.NodeInfo) XQueryCompiler(net.sf.saxon.s9api.XQueryCompiler) SaxonApiException(net.sf.saxon.s9api.SaxonApiException)

Example 7 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project sirix by sirixdb.

the class XQueryEvaluatorOutputStream method call.

@Override
public Void call() throws Exception {
    try {
        final Processor proc = new Processor(false);
        final Configuration config = proc.getUnderlyingConfiguration();
        final NodeInfo doc = new DocumentWrapper(mSession, config);
        final XQueryCompiler comp = proc.newXQueryCompiler();
        final XQueryExecutable exp = comp.compile(mExpression);
        if (mSerializer == null) {
            final Serializer out = new Serializer();
            out.setOutputProperty(Serializer.Property.METHOD, "xml");
            out.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes");
            out.setOutputStream(mOut);
            mSerializer = out;
        }
        final net.sf.saxon.s9api.XQueryEvaluator exe = exp.load();
        exe.setSource(doc);
        exe.run(mSerializer);
        return null;
    } catch (final SaxonApiException e) {
        LOGGER.error("Saxon Exception: " + e.getMessage(), e);
        throw e;
    }
}
Also used : XQueryExecutable(net.sf.saxon.s9api.XQueryExecutable) DocumentWrapper(org.sirix.saxon.wrapper.DocumentWrapper) Processor(net.sf.saxon.s9api.Processor) Configuration(net.sf.saxon.Configuration) NodeInfo(net.sf.saxon.om.NodeInfo) XQueryCompiler(net.sf.saxon.s9api.XQueryCompiler) SaxonApiException(net.sf.saxon.s9api.SaxonApiException) Serializer(net.sf.saxon.s9api.Serializer)

Example 8 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project sirix by sirixdb.

the class TestNodeWrapperXPath method testElementBCount.

@Test
public void testElementBCount() throws Exception {
    final XPathExpression findLine = xpe.compile("count(//b)");
    final NodeInfo doc = new DocumentWrapper(mHolder.getSession(), config);
    // Execute XPath.
    final double result = Double.parseDouble(findLine.evaluate(doc, XPathConstants.NUMBER).toString());
    assertNotNull(result);
    assertEquals(2D, result, 0D);
}
Also used : XPathExpression(javax.xml.xpath.XPathExpression) NodeInfo(net.sf.saxon.om.NodeInfo) Test(org.junit.Test)

Example 9 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project sirix by sirixdb.

the class TestNodeWrapperXPath method testB1.

@Test
public void testB1() throws Exception {
    xpe.setNamespaceContext(new DocNamespaceContext());
    final XPathExpression findLine = xpe.compile("//b[1]");
    final NodeInfo doc = new DocumentWrapper(mHolder.getSession(), config);
    // Execute XPath.
    final String result = (String) findLine.evaluate(doc, XPathConstants.STRING);
    assertNotNull(result);
    assertEquals("foo", result);
}
Also used : XPathExpression(javax.xml.xpath.XPathExpression) NodeInfo(net.sf.saxon.om.NodeInfo) Test(org.junit.Test)

Example 10 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project sirix by sirixdb.

the class TestNodeWrapperXPath method testDefaultNamespaceText2.

@Test
public void testDefaultNamespaceText2() throws Exception {
    xpe.setNamespaceContext(new DocNamespaceContext());
    final XPathExpression findLine = xpe.compile("//p:a/text()[2]");
    final NodeInfo doc = new DocumentWrapper(mHolder.getSession(), config);
    // Execute XPath.
    final String result = (String) findLine.evaluate(doc, XPathConstants.STRING);
    assertNotNull(result);
    assertEquals("oops2", result);
}
Also used : XPathExpression(javax.xml.xpath.XPathExpression) NodeInfo(net.sf.saxon.om.NodeInfo) Test(org.junit.Test)

Aggregations

NodeInfo (net.sf.saxon.om.NodeInfo)52 Test (org.junit.Test)21 XPathExpression (javax.xml.xpath.XPathExpression)16 Test (org.junit.jupiter.api.Test)14 Processor (net.sf.saxon.s9api.Processor)8 Configuration (net.sf.saxon.Configuration)7 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)5 DocumentWrapper (org.sirix.saxon.wrapper.DocumentWrapper)5 NameTest (net.sf.saxon.pattern.NameTest)4 SaxonApiException (net.sf.saxon.s9api.SaxonApiException)4 XQueryCompiler (net.sf.saxon.s9api.XQueryCompiler)3 XQueryExecutable (net.sf.saxon.s9api.XQueryExecutable)3 AxisIterator (net.sf.saxon.tree.iter.AxisIterator)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Item (net.sf.saxon.om.Item)2 Serializer (net.sf.saxon.s9api.Serializer)2 NodeReadTrx (org.sirix.api.NodeReadTrx)2 NodeList (org.w3c.dom.NodeList)2