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();
}
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);
}
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);
}
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());
}
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);
}
Aggregations