use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class XPathQueryTest method starAxis.
@Test
public void starAxis() throws XMLDBException {
final XQueryService service = storeXMLStringAndGetQueryService("numbers.xml", numbers);
ResourceSet result = service.queryResource("numbers.xml", "/*/item");
assertEquals("XPath: /*/item", 4, result.getSize());
result = service.queryResource("numbers.xml", "/test/*");
assertEquals("XPath: /test/*", 4, result.getSize());
result = service.queryResource("numbers.xml", "/test/descendant-or-self::*");
assertEquals("XPath: /test/descendant-or-self::*", 13, result.getSize());
result = service.queryResource("numbers.xml", "/*/*");
// Strange !!! Should be 8
assertEquals("XPath: /*/*", 4, result.getSize());
}
use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class XPathQueryTest method computation_bug_wiki_8.
/**
* Miscomputation of the expression context in where clause when no
* wrapper expression is used. Using, e.g. where data($x/@id) eq "id" works !
*/
@Test
public void computation_bug_wiki_8() throws XMLDBException {
final String xQuery = "declare option exist:serialize \"method=xml indent=no\"; " + "let $a := element node1 { attribute id {'id'}, " + "element node1 { '1'},element node2 { '2'} }" + "for $x in $a where $x/@id eq \"id\" return $x";
final XQueryService service = getQueryService();
final ResourceSet rs = service.query(xQuery);
assertEquals("testComputationBug_wiki_8", 1, rs.getSize());
assertEquals("testComputationBug_wiki_8", "<node1 id=\"id\"><node1>1</node1><node2>2</node2></node1>", rs.getResource(0).getContent().toString());
}
use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class XPathQueryTest method predicate_bug_andrzej.
@Test
public void predicate_bug_andrzej() throws XMLDBException {
final String xQuery = "doc('/db/test/predicates.xml')//elem1/elem2[ string-length( ./elem3 ) > 0][1]/elem3/text()";
final XQueryService service = storeXMLStringAndGetQueryService("predicates.xml", predicates);
final ResourceSet rs = service.query(xQuery);
assertEquals("testPredicateBUGAndrzej", 1, rs.getSize());
assertEquals("testPredicateBUGAndrzej", "val1", rs.getResource(0).getContent().toString());
}
use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class XPathQueryTest method virtualNodeset_bug_wiki_4.
/**
* Problem in VirtualNodeSet because it computes the wrong level
*
* @see http://wiki.exist-db.org/space/XQueryBugs
*/
@Test
public void virtualNodeset_bug_wiki_4() 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::*/child::b " + "return <a>{$node}</a>";
final XQueryService service = getQueryService();
final ResourceSet rs = service.query(xQuery);
assertEquals("VirtualNodesetBUG_wiki_4", 1, rs.getSize());
assertEquals("VirtualNodesetBUG_wiki_4", "<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 nestedPredicates_bug1533053.
/**
* @see http://sourceforge.net/tracker/index.php?func=detail&aid=1533053&group_id=17691&atid=117691
*/
@Test
public void nestedPredicates_bug1533053() throws XMLDBException, IOException, SAXException {
String xQuery = "let $doc := <objects>" + "<detail><class/><source><dynamic>false</dynamic></source></detail>" + "<detail><class/><source><dynamic>true</dynamic></source></detail>" + "</objects> " + "let $matches := $doc/detail[source[dynamic='false'] or class] " + "return count($matches) eq 2";
XQueryService service = getQueryService();
ResourceSet rs = service.query(xQuery);
assertEquals(1, rs.getSize());
assertEquals("true", rs.getResource(0).getContent().toString());
xQuery = "let $xml := <test><element>" + "<complexType><attribute name=\"design\" fixed=\"1\"/></complexType>" + "</element></test> " + "return $xml//element[complexType/attribute[@name eq \"design\"]/@fixed eq \"1\"]";
service = getQueryService();
service.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
service.setProperty(OutputKeys.INDENT, "no");
rs = service.query(xQuery);
assertEquals(1, rs.getSize());
assertXMLEqual("<element><complexType><attribute name=\"design\" fixed=\"1\"/></complexType></element>", rs.getResource(0).getContent().toString());
}
Aggregations