Search in sources :

Example 11 with NodeInfo

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

the class TestNodeWrapperXPath method testElementACount.

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

Example 12 with NodeInfo

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

the class TestNodeWrapperXPath method testNamespaceAttributeCount.

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

Example 13 with NodeInfo

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

the class TestNodeWrapperXPath method testDefaultNamespaceText1.

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

Example 14 with NodeInfo

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

the class TestNodeWrapperXPath method testBAll.

@SuppressWarnings("unchecked")
@Test
public void testBAll() throws Exception {
    xpe.setNamespaceContext(new DocNamespaceContext());
    final XPathExpression findLine = xpe.compile("//b");
    final NodeInfo doc = new DocumentWrapper(mHolder.getSession(), config);
    // Execute XPath.
    final ArrayList<NodeWrapper> result = (ArrayList<NodeWrapper>) findLine.evaluate(doc, XPathConstants.NODESET);
    assertNotNull(result);
    assertEquals(5, result.get(0).getKey());
    assertEquals(9, result.get(1).getKey());
    final NodeReadTrx rtx = mHolder.getSession().beginNodeReadTrx();
    rtx.moveTo(result.get(0).getKey());
    assertEquals("b", rtx.getName().getLocalName());
    rtx.moveTo(result.get(1).getKey());
    assertEquals("b", rtx.getName().getLocalName());
}
Also used : XPathExpression(javax.xml.xpath.XPathExpression) NodeReadTrx(org.sirix.api.NodeReadTrx) NodeInfo(net.sf.saxon.om.NodeInfo) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 15 with NodeInfo

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

the class TestNodeWrapperXPath method testB2.

@Test
public void testB2() throws Exception {
    xpe.setNamespaceContext(new DocNamespaceContext());
    final XPathExpression findLine = xpe.compile("//b[2]");
    final NodeInfo doc = new DocumentWrapper(mHolder.getSession(), config);
    // Execute XPath.
    final String result = (String) findLine.evaluate(doc, XPathConstants.STRING);
    assertNotNull(result);
    assertEquals("bar", 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