use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class XPathQueryTest method ancestor.
/**
* test involving ancestor::
* >>>>>>> currently this produces variable corruption :
* The result is the ancestor <<<<<<<<<<
*/
@Test
public void ancestor() throws XMLDBException {
final XQueryService service = storeXMLStringAndGetQueryService("numbers.xml", numbers);
final String query = "let $all_items := /test/item " + "(: Note: variable non used but computed anyway :)" + "let $unused_variable :=" + " for $one_item in $all_items " + " / ancestor::* (: <<<<< if you remove this line all is normal :)" + " return 'foo'" + "return $all_items";
final ResourceSet result = service.queryResource("numbers.xml", query);
assertEquals(4, result.getSize());
}
use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class XPathQueryTest method preserveSpace.
@Test
public void preserveSpace() throws XMLDBException, IOException, SAXException {
final XQueryService service = storeXMLStringAndGetQueryService("whitespace.xml", ws);
final ResourceSet result = service.queryResource("whitespace.xml", "//text");
assertEquals(2, result.getSize());
String item = result.getResource(0).getContent().toString();
assertXMLEqual("<text> </text>", item);
item = result.getResource(1).getContent().toString();
assertXMLEqual("<text xml:space=\"default\"> </text>", item);
}
use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class XPathQueryTest method predicates_bug1460610.
/**
* @see http://sourceforge.net/tracker/index.php?func=detail&aid=1460610&group_id=17691&atid=117691
*/
@Test
public void predicates_bug1460610() throws XMLDBException {
final String xQuery = "(1, 2, 3)[ . lt 3]";
final XQueryService service = getQueryService();
final ResourceSet rs = service.query(xQuery);
assertEquals("SFBUG 1460610 nr of results", 2, rs.getSize());
assertEquals("SFBUG 1460610 1st result", "1", rs.getResource(0).getContent().toString());
assertEquals("SFBUG 1460610 2nd result", "2", rs.getResource(1).getContent().toString());
}
use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class XPathQueryTest method root.
@Test
public void root() throws XMLDBException {
storeXMLStringAndGetQueryService("nested2.xml", nested2);
final XQueryService service = storeXMLStringAndGetQueryService("numbers.xml", numbers);
String query = "let $doc := <a><b/></a> return root($doc)";
ResourceSet result = service.queryResource("numbers.xml", query);
assertEquals("XPath: " + query, 1, result.getSize());
final XMLResource resource = (XMLResource) result.getResource(0);
Node node = resource.getContentAsDOM();
// Oh dear ! Don't tell me that *I* have written this :'( -pb
if (node.getNodeType() == Node.DOCUMENT_NODE) {
node = node.getFirstChild();
}
assertEquals("XPath: " + query, "a", node.getLocalName());
query = "let $c := (<a/>,<b/>,<c/>,<d/>,<e/>) return count($c/root())";
result = service.queryResource("numbers.xml", query);
assertEquals("5", result.getResource(0).getContent().toString());
}
use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class XPathQueryTest method followingSiblingAxis_memtree.
@Test
public void followingSiblingAxis_memtree() throws XMLDBException, IOException, SAXException {
final XQueryService service = getQueryService();
service.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
service.setProperty(OutputKeys.INDENT, "no");
ResourceSet rs = service.query("(<a/>, <b/>, <c/>)/following-sibling::*");
assertEquals(0, rs.getSize());
rs = service.query("let $doc := <doc><div id='1'><div id='2'/></div><div id='3'/></doc> " + "return $doc/div[1]/following-sibling::div");
assertEquals(1, rs.getSize());
assertXMLEqual("<div id='3'/>", rs.getResource(0).getContent().toString());
rs = service.query("let $doc := document { <!-- 1 -->,<!-- 2 -->,<test/>,<!-- 3 --> } return $doc/test/following-sibling::node()");
assertEquals(1, rs.getSize());
assertEquals("<!-- 3 -->", rs.getResource(0).getContent().toString());
rs = service.query("let $doc := document { <!-- 1 -->,<!-- 2 -->,<test/>,<!-- 3 --> } return $doc/node()[1]/following-sibling::node()");
assertEquals(3, rs.getSize());
assertEquals("<!-- 2 -->", rs.getResource(0).getContent().toString());
assertXMLEqual("<test/>", rs.getResource(1).getContent().toString());
assertEquals("<!-- 3 -->", rs.getResource(2).getContent().toString());
rs = service.query("let $doc := document { <!-- 1 -->,<!-- 2 -->,<test/>,<!-- 3 --> } return $doc/comment()[1]/following-sibling::comment()[1]");
assertEquals(1, rs.getSize());
assertEquals("<!-- 2 -->", rs.getResource(0).getContent().toString());
rs = service.query("let $doc := document { <!-- 1 -->,<!-- 2 -->,<test/>,<!-- 3 --> } return $doc/comment()[1]/following-sibling::comment()[2]");
assertEquals(1, rs.getSize());
assertEquals("<!-- 3 -->", rs.getResource(0).getContent().toString());
rs = service.query("let $elem := <a b='c' bb='cc'/> return $elem/@b/following-sibling::*");
assertEquals(0, rs.getSize());
rs = service.query("let $doc := document { <x><y n=\"1\"/><y n=\"2\"/><y n=\"3\"/></x> } return $doc //y[@n eq '2']/following-sibling::*:y");
assertEquals(1, rs.getSize());
rs = service.query("let $doc := document { <x><y n=\"1\"/><y n=\"2\"/><y n=\"3\"/></x> } return $doc //y[@n eq '2']/following-sibling::y");
assertEquals(1, rs.getSize());
rs = service.query("let $doc := document { <y><y n=\"1\"/><y n=\"2\"/><y n=\"3\"/></y> } return $doc //y[@n eq '2']/following-sibling::*:y");
assertEquals(1, rs.getSize());
rs = service.query("let $doc := document { <y><y n=\"1\"/><y n=\"2\"/><y n=\"3\"/></y> } return $doc //y[@n eq '2']/following-sibling::y");
assertEquals(1, rs.getSize());
}
Aggregations