Search in sources :

Example 36 with XQueryService

use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.

the class XPathQueryTest method virtualNodeset_bug_wiki_5.

/**
 * Problem in VirtualNodeSet because it computes the wrong level
 *
 * @see http://wiki.exist-db.org/space/XQueryBugs
 */
@Test
public void virtualNodeset_bug_wiki_5() throws XMLDBException {
    final String xQuery = "declare option exist:serialize \"method=xml indent=no\"; " + "let $node := (<c id=\"OK\"><b id=\"cool\"/>" + "</c>)/descendant-or-self::*/descendant::b return <a>{$node}</a>";
    final XQueryService service = getQueryService();
    final ResourceSet rs = service.query(xQuery);
    assertEquals("VirtualNodesetBUG_wiki_5", 1, rs.getSize());
    assertEquals("VirtualNodesetBUG_wiki_5", "<a><b id=\"cool\"/></a>", rs.getResource(0).getContent().toString());
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) XQueryService(org.xmldb.api.modules.XQueryService)

Example 37 with XQueryService

use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.

the class XPathQueryTest method intersect.

@Test
public void intersect() throws XMLDBException {
    final XQueryService service = getQueryService();
    String query = "()  intersect ()";
    queryAndAssert(service, query, 0, "");
    query = "()  intersect  (1)";
    queryAndAssert(service, query, 0, "");
    query = "(1)  intersect  ()";
    queryAndAssert(service, query, 0, "");
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) XQueryService(org.xmldb.api.modules.XQueryService)

Example 38 with XQueryService

use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.

the class XPathQueryTest method followingAxis.

@Test
public void followingAxis() throws XMLDBException, IOException, SAXException {
    final XQueryService service = storeXMLStringAndGetQueryService("siblings.xml", siblings);
    service.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    service.setProperty(OutputKeys.INDENT, "no");
    queryResource(service, "siblings.xml", "//a/s[. = 'B']/following::s", 3);
    queryResource(service, "siblings.xml", "//a/s[. = 'B']/following::n", 4);
    ResourceSet result = queryResource(service, "siblings.xml", "//a/s[. = 'B']/following::s[1]", 1);
    assertXMLEqual("<s>Z</s>", result.getResource(0).getContent().toString());
    result = queryResource(service, "siblings.xml", "//a/s[. = 'B']/following::s[2]", 1);
    assertXMLEqual("<s>C</s>", result.getResource(0).getContent().toString());
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) XQueryService(org.xmldb.api.modules.XQueryService)

Example 39 with XQueryService

use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.

the class XPathQueryTest method parentAxis.

@Test
public void parentAxis() throws XMLDBException {
    XQueryService service = storeXMLStringAndGetQueryService("nested2.xml", nested2);
    queryResource(service, "nested2.xml", "(<a/>, <b/>, <c/>)/parent::*", 0);
    queryResource(service, "nested2.xml", "/RootElement//ChildB/parent::*", 1);
    queryResource(service, "nested2.xml", "/RootElement//ChildB/parent::*/ChildB", 1);
    queryResource(service, "nested2.xml", "/RootElement/ChildA/parent::*/ChildA/ChildB", 1);
    service = storeXMLStringAndGetQueryService("numbers2.xml", numbers2);
    service.setNamespace("n", "http://numbers.org");
    queryResource(service, "numbers2.xml", "//n:price[. = 18.4]/parent::*[@id = '3']", 1);
    queryResource(service, "numbers2.xml", "//n:price[. = 18.4]/parent::n:item[@id = '3']", 1);
    queryResource(service, "numbers2.xml", "//n:price/parent::n:item[@id = '3']", 1);
    ResourceSet result = queryResource(service, "numbers2.xml", "//n:price[. = 18.4]/parent::n:*/string(@id)", 1);
    assertEquals("3", result.getResource(0).getContent().toString());
    result = queryResource(service, "numbers2.xml", "//n:price[. = 18.4]/parent::*:item/string(@id)", 1);
    assertEquals("3", result.getResource(0).getContent().toString());
    result = queryResource(service, "numbers2.xml", "//n:price[. = 18.4]/../string(@id)", 1);
    assertEquals("3", result.getResource(0).getContent().toString());
    result = queryResource(service, "numbers2.xml", "//n:price[. = 18.4]/parent::n:item/string(@id)", 1);
    assertEquals("3", result.getResource(0).getContent().toString());
    queryResource(service, "numbers2.xml", "for $price in //n:price where $price/parent::*[@id = '3']/n:stock = '5' return $price", 1);
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) XQueryService(org.xmldb.api.modules.XQueryService)

Example 40 with XQueryService

use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.

the class XPathQueryTest method precedingAxis.

@Test
public void precedingAxis() throws XMLDBException {
    final XQueryService service = storeXMLStringAndGetQueryService("siblings.xml", siblings);
    service.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    service.setProperty(OutputKeys.INDENT, "no");
    queryResource(service, "siblings.xml", "//a/s[. = 'B']/preceding::s", 2);
    queryResource(service, "siblings.xml", "//a/s[. = 'C']/preceding::s", 4);
    queryResource(service, "siblings.xml", "//a/n[. = '3']/preceding::s", 3);
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) XQueryService(org.xmldb.api.modules.XQueryService)

Aggregations

XQueryService (org.xmldb.api.modules.XQueryService)129 EXistXQueryService (org.exist.xmldb.EXistXQueryService)71 XMLResource (org.xmldb.api.modules.XMLResource)33 ResourceSet (org.xmldb.api.base.ResourceSet)29 Test (org.junit.Test)28 Resource (org.xmldb.api.base.Resource)8 Node (org.w3c.dom.Node)6 EXistResource (org.exist.xmldb.EXistResource)5 Document (org.w3c.dom.Document)5 Collection (org.xmldb.api.base.Collection)5 Source (javax.xml.transform.Source)4 IndexQueryService (org.exist.xmldb.IndexQueryService)4 CompiledExpression (org.xmldb.api.base.CompiledExpression)4 XMLDBException (org.xmldb.api.base.XMLDBException)4 Diff (org.xmlunit.diff.Diff)4 Path (java.nio.file.Path)2 XmlRpcTest (org.exist.xmlrpc.XmlRpcTest)2 StringWriter (java.io.StringWriter)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1