Search in sources :

Example 81 with XQueryService

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());
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) XQueryService(org.xmldb.api.modules.XQueryService)

Example 82 with XQueryService

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());
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) XQueryService(org.xmldb.api.modules.XQueryService)

Example 83 with XQueryService

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());
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) XQueryService(org.xmldb.api.modules.XQueryService)

Example 84 with XQueryService

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());
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) XQueryService(org.xmldb.api.modules.XQueryService)

Example 85 with XQueryService

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