Search in sources :

Example 81 with XPathQueryService

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());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet) XMLResource(org.xmldb.api.modules.XMLResource)

Example 82 with XPathQueryService

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());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 83 with XPathQueryService

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());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 84 with XPathQueryService

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());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 85 with XPathQueryService

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());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Aggregations

XPathQueryService (org.xmldb.api.modules.XPathQueryService)148 ResourceSet (org.xmldb.api.base.ResourceSet)123 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)92 XMLResource (org.xmldb.api.modules.XMLResource)60 Collection (org.xmldb.api.base.Collection)31 Test (org.junit.Test)22 Resource (org.xmldb.api.base.Resource)18 XMLDBException (org.xmldb.api.base.XMLDBException)14 EXistResource (org.exist.xmldb.EXistResource)10 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)9 XUpdateQueryService (org.xmldb.api.modules.XUpdateQueryService)8 IndexQueryService (org.exist.xmldb.IndexQueryService)6 IOException (java.io.IOException)3 ResourceIterator (org.xmldb.api.base.ResourceIterator)3 BinaryResource (org.xmldb.api.modules.BinaryResource)3 MalformedURLException (java.net.MalformedURLException)2 Path (java.nio.file.Path)2 Node (org.w3c.dom.Node)2 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1