Search in sources :

Example 36 with NodeInfo

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

the class TestNodeWrapperXPath method testDefaultNamespaceTextAll.

@SuppressWarnings("unchecked")
@Test
public void testDefaultNamespaceTextAll() throws Exception {
    xpe.setNamespaceContext(new DocNamespaceContext());
    final XPathExpression findLine = xpe.compile("//p:a/text()");
    final NodeInfo doc = new DocumentWrapper(mHolder.getSession(), config);
    // Execute XPath.
    final ArrayList<NodeWrapper> result = (ArrayList<NodeWrapper>) findLine.evaluate(doc, XPathConstants.NODESET);
    assertNotNull(result);
    final NodeReadTrx rtx = mHolder.getSession().beginNodeReadTrx();
    rtx.moveTo(result.get(0).getKey());
    assertEquals("oops1", rtx.getValue());
    rtx.moveTo(result.get(1).getKey());
    assertEquals("oops2", rtx.getValue());
    rtx.moveTo(result.get(2).getKey());
    assertEquals("oops3", rtx.getValue());
    rtx.close();
}
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 37 with NodeInfo

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

the class TestNodeWrapperXPath method testDefaultNamespaceText3.

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

Example 38 with NodeInfo

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

the class TestNodeWrapperXPath method testAttributeValue.

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

Example 39 with NodeInfo

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

the class TestNodeWrapperXPath method testExample.

@Test
public void testExample() throws Exception {
    final String[] expressions = { "count(//b)", "count(//p:a)", "//p:a/@i", "//p:a/@p:i", "//b[1]/text()", "//b[2]", "//b[1]", "//b[2]/text()", "//p:a/text()" };
    final NodeInfo doc = new DocumentWrapper(mHolder.getSession(), config);
    final Object[] expectedResults = { 2D, 1D, "j", "", "foo", // "<b p:x=\"y\"><c/>bar</b>",
    "bar", "foo", // "<b>foo<c/></b>",
    "bar", "oops1 oops2 oops3" };
    Object[] result = { "", "", "", 0D, "", "", "", "", "" };
    final QName[] xpathConstants = { XPathConstants.NUMBER, XPathConstants.NUMBER, XPathConstants.STRING, XPathConstants.STRING, XPathConstants.STRING, XPathConstants.STRING, XPathConstants.STRING, XPathConstants.STRING, XPathConstants.NODESET };
    final boolean[] namespaces = { false, true, true, false, false, false, false, false, true };
    test(expressions, doc, expectedResults, result, xpathConstants, namespaces, new DocNamespaceContext());
}
Also used : NodeInfo(net.sf.saxon.om.NodeInfo) QName(javax.xml.namespace.QName) Test(org.junit.Test)

Example 40 with NodeInfo

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

the class TestNodeWrapperXPath method testAttributeCount.

@Test
public void testAttributeCount() throws Exception {
    xpe.setNamespaceContext(new DocNamespaceContext());
    final XPathExpression findLine = xpe.compile("count(//p:a/@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(1D, result, 0D);
}
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