Search in sources :

Example 21 with XQueryService

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

the class XPathQueryTest method ancestor.

/**
 * test involving ancestor::
 * >>>>>>> currently this produces variable corruption :
 * 			The result is the ancestor <<<<<<<<<<
 */
@Test
public void ancestor() throws XMLDBException {
    final XQueryService service = storeXMLStringAndGetQueryService("numbers.xml", numbers);
    final String query = "let $all_items := /test/item " + "(: Note: variable non used but computed anyway :)" + "let $unused_variable :=" + "	for $one_item in $all_items " + "			/ ancestor::*	(: <<<<< if you remove this line all is normal :)" + "		return 'foo'" + "return $all_items";
    final ResourceSet result = service.queryResource("numbers.xml", query);
    assertEquals(4, result.getSize());
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) XQueryService(org.xmldb.api.modules.XQueryService)

Example 22 with XQueryService

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

the class XPathQueryTest method preserveSpace.

@Test
public void preserveSpace() throws XMLDBException, IOException, SAXException {
    final XQueryService service = storeXMLStringAndGetQueryService("whitespace.xml", ws);
    final ResourceSet result = service.queryResource("whitespace.xml", "//text");
    assertEquals(2, result.getSize());
    String item = result.getResource(0).getContent().toString();
    assertXMLEqual("<text> </text>", item);
    item = result.getResource(1).getContent().toString();
    assertXMLEqual("<text xml:space=\"default\"> </text>", item);
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) XQueryService(org.xmldb.api.modules.XQueryService)

Example 23 with XQueryService

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

the class XPathQueryTest method predicates_bug1460610.

/**
 * @see http://sourceforge.net/tracker/index.php?func=detail&aid=1460610&group_id=17691&atid=117691
 */
@Test
public void predicates_bug1460610() throws XMLDBException {
    final String xQuery = "(1, 2, 3)[ . lt 3]";
    final XQueryService service = getQueryService();
    final ResourceSet rs = service.query(xQuery);
    assertEquals("SFBUG 1460610 nr of results", 2, rs.getSize());
    assertEquals("SFBUG 1460610 1st result", "1", rs.getResource(0).getContent().toString());
    assertEquals("SFBUG 1460610 2nd result", "2", rs.getResource(1).getContent().toString());
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) XQueryService(org.xmldb.api.modules.XQueryService)

Example 24 with XQueryService

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

the class XPathQueryTest method root.

@Test
public void root() throws XMLDBException {
    storeXMLStringAndGetQueryService("nested2.xml", nested2);
    final XQueryService service = storeXMLStringAndGetQueryService("numbers.xml", numbers);
    String query = "let $doc := <a><b/></a> return root($doc)";
    ResourceSet result = service.queryResource("numbers.xml", query);
    assertEquals("XPath: " + query, 1, result.getSize());
    final XMLResource resource = (XMLResource) result.getResource(0);
    Node node = resource.getContentAsDOM();
    // Oh dear ! Don't tell me that *I* have written this :'( -pb
    if (node.getNodeType() == Node.DOCUMENT_NODE) {
        node = node.getFirstChild();
    }
    assertEquals("XPath: " + query, "a", node.getLocalName());
    query = "let $c := (<a/>,<b/>,<c/>,<d/>,<e/>) return count($c/root())";
    result = service.queryResource("numbers.xml", query);
    assertEquals("5", result.getResource(0).getContent().toString());
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) XQueryService(org.xmldb.api.modules.XQueryService) Node(org.w3c.dom.Node) XMLResource(org.xmldb.api.modules.XMLResource)

Example 25 with XQueryService

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

the class XPathQueryTest method followingSiblingAxis_memtree.

@Test
public void followingSiblingAxis_memtree() throws XMLDBException, IOException, SAXException {
    final XQueryService service = getQueryService();
    service.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    service.setProperty(OutputKeys.INDENT, "no");
    ResourceSet rs = service.query("(<a/>, <b/>, <c/>)/following-sibling::*");
    assertEquals(0, rs.getSize());
    rs = service.query("let $doc := <doc><div id='1'><div id='2'/></div><div id='3'/></doc> " + "return $doc/div[1]/following-sibling::div");
    assertEquals(1, rs.getSize());
    assertXMLEqual("<div id='3'/>", rs.getResource(0).getContent().toString());
    rs = service.query("let $doc := document { <!-- 1 -->,<!-- 2 -->,<test/>,<!-- 3 --> } return $doc/test/following-sibling::node()");
    assertEquals(1, rs.getSize());
    assertEquals("<!-- 3 -->", rs.getResource(0).getContent().toString());
    rs = service.query("let $doc := document { <!-- 1 -->,<!-- 2 -->,<test/>,<!-- 3 --> } return $doc/node()[1]/following-sibling::node()");
    assertEquals(3, rs.getSize());
    assertEquals("<!-- 2 -->", rs.getResource(0).getContent().toString());
    assertXMLEqual("<test/>", rs.getResource(1).getContent().toString());
    assertEquals("<!-- 3 -->", rs.getResource(2).getContent().toString());
    rs = service.query("let $doc := document { <!-- 1 -->,<!-- 2 -->,<test/>,<!-- 3 --> } return $doc/comment()[1]/following-sibling::comment()[1]");
    assertEquals(1, rs.getSize());
    assertEquals("<!-- 2 -->", rs.getResource(0).getContent().toString());
    rs = service.query("let $doc := document { <!-- 1 -->,<!-- 2 -->,<test/>,<!-- 3 --> } return $doc/comment()[1]/following-sibling::comment()[2]");
    assertEquals(1, rs.getSize());
    assertEquals("<!-- 3 -->", rs.getResource(0).getContent().toString());
    rs = service.query("let $elem := <a b='c' bb='cc'/> return $elem/@b/following-sibling::*");
    assertEquals(0, rs.getSize());
    rs = service.query("let $doc := document { <x><y n=\"1\"/><y n=\"2\"/><y n=\"3\"/></x> } return $doc //y[@n eq '2']/following-sibling::*:y");
    assertEquals(1, rs.getSize());
    rs = service.query("let $doc := document { <x><y n=\"1\"/><y n=\"2\"/><y n=\"3\"/></x> } return $doc //y[@n eq '2']/following-sibling::y");
    assertEquals(1, rs.getSize());
    rs = service.query("let $doc := document { <y><y n=\"1\"/><y n=\"2\"/><y n=\"3\"/></y> } return $doc //y[@n eq '2']/following-sibling::*:y");
    assertEquals(1, rs.getSize());
    rs = service.query("let $doc := document { <y><y n=\"1\"/><y n=\"2\"/><y n=\"3\"/></y> } return $doc //y[@n eq '2']/following-sibling::y");
    assertEquals(1, rs.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