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());
}
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("<", "<").replace(">", ">") + "</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());
}
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);
}
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());
}
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());
}
Aggregations