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());
}
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, "");
}
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());
}
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);
}
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);
}
Aggregations