Search in sources :

Example 91 with XQueryService

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

the class XPathQueryTest method ids_memtree.

@Ignore("Not yet supported in eXist")
@Test
public void ids_memtree() throws XMLDBException {
    final XQueryService service = getQueryService();
    ResourceSet result = service.query("document { " + ids_content + " }//a/id(@ref)");
    assertEquals(1, result.getSize());
    result = service.query("document { " + ids_content + " }/test/id(//a/@ref)");
    assertEquals(1, result.getSize());
    result = service.query("document { " + ids_content + " }//a/id(@ref)/name");
    assertEquals(1, result.getSize());
    Resource r = result.getResource(0);
    assertEquals("<name>one</name>", r.getContent().toString());
    result = service.query("document { " + ids_content + " }//d/id(@ref)/name");
    r = result.getResource(0);
    assertEquals("<name>two</name>", r.getContent().toString());
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) XQueryService(org.xmldb.api.modules.XQueryService) XMLResource(org.xmldb.api.modules.XMLResource)

Example 92 with XQueryService

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

the class XPathQueryTest method cdataComputedDom.

@Test
public void cdataComputedDom() throws XMLDBException {
    final XQueryService service = getQueryService();
    String query = "document {\n" + cdata_xml + "\n" + "}";
    ResourceSet result = queryAndAssert(service, query, 1, null);
    final String expected = "<elem1>" + cdata_content.replace("<", "&lt;").replace(">", "&gt;") + "</elem1>";
    assertEquals(expected, result.getResource(0).getContent().toString());
    query = "declare namespace output = \"http://www.w3.org/2010/xslt-xquery-serialization\";\n" + "declare option output:cdata-section-elements \"elem1\";\n" + "document {\n" + cdata_xml + "\n" + "}";
    result = queryAndAssert(service, query, 1, null);
    assertEquals(cdata_xml, result.getResource(0).getContent().toString());
    query = "fn:serialize(document {" + cdata_xml + "},\n" + "<output:serialization-parameters xmlns:output = \"http://www.w3.org/2010/xslt-xquery-serialization\">\n" + "    <output:method value=\"xml\"/>\n" + "    <output:cdata-section-elements value=\"elem1\"/>\n" + "</output:serialization-parameters>)";
    result = queryAndAssert(service, query, 1, null);
    assertEquals(cdata_xml, result.getResource(0).getContent().toString());
    query = "fn:serialize(document {" + cdata_xml + "},\n" + "map {\n" + "    \"method\": \"xml\",\n" + "    \"cdata-section-elements\": xs:QName(\"elem1\")\n" + "})";
    result = queryAndAssert(service, query, 1, null);
    assertEquals(cdata_xml, result.getResource(0).getContent().toString());
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) XQueryService(org.xmldb.api.modules.XQueryService)

Example 93 with XQueryService

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

the class XPathQueryTest method idsOnEmptyCollection.

@Test
public void idsOnEmptyCollection() throws XMLDBException {
    final Collection root = DatabaseManager.getCollection(getBaseUri(), "admin", "");
    final CollectionManagementService service = (CollectionManagementService) root.getService("CollectionManagementService", "1.0");
    final Collection emptyCollection = service.createCollection("empty");
    final XQueryService queryService = (XQueryService) emptyCollection.getService("XPathQueryService", "1.0");
    queryAndAssert(queryService, "/*", 0, null);
    queryAndAssert(queryService, "/id('foo')", 0, null);
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) EXistXQueryService(org.exist.xmldb.EXistXQueryService) XQueryService(org.xmldb.api.modules.XQueryService)

Example 94 with XQueryService

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

the class XPathQueryTest method starAxisConstraints3.

@Test
public void starAxisConstraints3() throws XMLDBException {
    final XQueryService service = storeXMLStringAndGetQueryService("namespaces.xml", namespaces);
    service.setNamespace("t", "http://www.foo.com");
    final String query = "// * [ . = 'Test Document' ]";
    final ResourceSet result = service.queryResource("namespaces.xml", query);
    assertEquals("XPath: " + query, 1, result.getSize());
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) XQueryService(org.xmldb.api.modules.XQueryService)

Example 95 with XQueryService

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

the class XPathQueryTest method parentSelfAxis.

@Test
public void parentSelfAxis() throws XMLDBException {
    final XQueryService service = storeXMLStringAndGetQueryService("nested2.xml", nested2);
    storeXMLStringAndGetQueryService("numbers.xml", numbers);
    queryResource(service, "nested2.xml", "/RootElement/descendant::*/parent::ChildA", 1);
    queryResource(service, "nested2.xml", "/RootElement/descendant::*[self::ChildB]/parent::RootElement", 0);
    queryResource(service, "nested2.xml", "/RootElement/descendant::*[self::ChildA]/parent::RootElement", 1);
    queryResource(service, "nested2.xml", "let $a := ('', 'b', '', '') for $b in $a[.] return <blah>{$b}</blah>", 1);
    final String query = "let $doc := <root><page><a>a</a><b>b</b></page></root>" + "return " + "for $element in $doc/page/* " + "return " + "if($element[self::a] or $element[self::b]) then (<found/>) else (<notfound/>)";
    final ResourceSet result = service.queryResource("numbers.xml", query);
    assertEquals(2, result.getSize());
}
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