use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class XQueryTest method virtualNodesets.
@Test
public void virtualNodesets() throws XMLDBException, IOException, SAXException {
ResourceSet result;
String query;
@SuppressWarnings("unused") XMLResource resu;
@SuppressWarnings("unused") boolean exceptionThrown;
@SuppressWarnings("unused") String message;
XPathQueryService service = storeXMLStringAndGetQueryService(NUMBERS_XML, numbers);
service.setProperty(OutputKeys.INDENT, "no");
query = "let $node := (<c id='OK'><b id='cool'/></c>)/descendant::*/attribute::id " + "return <a>{$node}</a>";
result = service.queryResource(NUMBERS_XML, query);
assertEquals("XQuery: " + query, 1, result.getSize());
assertXMLEqual("<a id='cool'/>", ((XMLResource) result.getResource(0)).getContent().toString());
query = "let $node := (<c id='OK'><b id='cool'/></c>)/descendant-or-self::*/child::b " + "return <a>{$node}</a>";
result = service.queryResource(NUMBERS_XML, query);
assertEquals("XQuery: " + query, 1, result.getSize());
assertXMLEqual("<a><b id='cool'/></a>", ((XMLResource) result.getResource(0)).getContent().toString());
query = "let $node := (<c id='OK'><b id='cool'/></c>)/descendant-or-self::*/descendant::b " + "return <a>{$node}</a>";
result = service.queryResource(NUMBERS_XML, query);
assertEquals("XQuery: " + query, 1, result.getSize());
assertXMLEqual("<a><b id='cool'/></a>", ((XMLResource) result.getResource(0)).getContent().toString());
query = "let $doc := <a id='a'><b id='b'/></a> " + "return $doc/*/(<id>{@id}</id>)";
result = service.queryResource(NUMBERS_XML, query);
assertEquals("XQuery: " + query, 1, result.getSize());
assertXMLEqual("<id id='b' />", ((XMLResource) result.getResource(0)).getContent().toString());
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class XQueryTest method stringOfEmptySequence_1841105.
/**
* In a path expression, a step returning an empty sequence stops the evaluation
* (and return an empty sequence) as confirmed by Michael Kay on the XQuery mailing list
*
* @see http://sourceforge.net/support/tracker.php?aid=1841105
*/
@Test
public void stringOfEmptySequence_1841105() throws XMLDBException {
// OK
String query = "empty( ()/string() )";
XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
ResourceSet result = service.query(query);
assertEquals(1, result.getSize());
assertEquals(query, "true", result.getResource(0).getContent().toString());
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class XQueryTest method textConstructor.
@Test
public void textConstructor() throws XMLDBException {
String query = "text{ \"a\" }, text{ \"b\" }, text{ \"c\" }, text{ \"d\" }";
XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
ResourceSet result = service.query(query);
assertEquals("XQuery: " + query, 4, result.getSize());
assertEquals("XQuery: " + query, "a", result.getResource(0).getContent().toString());
assertEquals("XQuery: " + query, "b", result.getResource(1).getContent().toString());
assertEquals("XQuery: " + query, "c", result.getResource(2).getContent().toString());
assertEquals("XQuery: " + query, "d", result.getResource(3).getContent().toString());
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class XQueryTest method precedence.
@Test
public void precedence() throws XMLDBException {
ResourceSet result;
String query;
@SuppressWarnings("unused") boolean exceptionThrown;
@SuppressWarnings("unused") String message;
XPathQueryService service = storeXMLStringAndGetQueryService(NUMBERS_XML, numbers);
query = "xquery version \"1.0\";\n" + "declare namespace blah=\"blah\";\n" + "declare variable $blah:param {\"value-1\"};\n" + "let $blah:param := \"value-2\"\n" + "(:: FLWOR expressions have a higher precedence than the comma operator ::)\n" + "return $blah:param, $blah:param ";
result = service.query(query);
assertEquals("XQuery: " + query, 2, result.getSize());
assertEquals("XQuery: " + query, "value-2", ((XMLResource) result.getResource(0)).getContent());
assertEquals("XQuery: " + query, "value-1", ((XMLResource) result.getResource(1)).getContent());
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class XQueryTest method cce_IndexOf_1769086.
/**
* @see http://sourceforge.net/support/tracker.php?aid=1769086
*/
@Test
public void cce_IndexOf_1769086() throws XMLDBException {
String query = "(\"One\", \"Two\", \"Three\")[index-of((\"1\", \"2\", \"3\"), \"2\")]";
XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
ResourceSet result = service.query(query);
assertEquals(1, result.getSize());
assertEquals("First", "Two", result.getResource(0).getContent().toString());
}
Aggregations