Search in sources :

Example 66 with XPathQueryService

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

the class XQueryTest method cce_SaxException.

@Test
public void cce_SaxException() throws XMLDBException {
    String xmldocument = "<a><b><c>mmm</c></b></a>";
    String location = "ccesax.xml";
    String query = "declare namespace xmldb = \"http://exist-db.org/xquery/xmldb\"; " + "declare option exist:serialize 'indent=no';" + "let $results := doc(\"ccesax.xml\")/element() " + "let $output := let $body := <e>{$results/b/c}</e>  return <d>{$body}</d> " + "let $id := $output/e/c " + "let $store := xmldb:store(\"/db\", \"output.xml\", $output)" + "return doc('/db/output.xml')";
    // String output = "<d><b><c>mmm</c></b></d>";
    String output = "<d><e><c>mmm</c></e></d>";
    XPathQueryService service = storeXMLStringAndGetQueryService(location, xmldocument);
    ResourceSet result = service.query(query);
    assertEquals("XQuery: " + query, 1, result.getSize());
    assertEquals("XQuery: " + query, output, result.getResource(0).getContent().toString());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 67 with XPathQueryService

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

the class XQueryTest method cardinalityIssues_1740886.

/**
 * @see http://sourceforge.net/support/tracker.php?aid=1740886
 */
@Test
public void cardinalityIssues_1740886() throws XMLDBException, IOException, SAXException {
    String xmldoc = "<Foo><Bar/><Bar/><Bar/></Foo>";
    String query = "declare namespace tst = \"urn:test\"; " + "declare option exist:serialize 'indent=no';" + // ======
    "declare function tst:bar( $foo as element(Foo) ) as element(Foo) { " + "let $dummy := $foo/Bar " + "return $foo }; " + // ====== if you leave /test out......
    "let $foo := doc(\"/db/test/foo.xml\")/element() " + "return tst:bar($foo)";
    XPathQueryService service = storeXMLStringAndGetQueryService("foo.xml", xmldoc);
    ResourceSet result = service.query(query);
    assertEquals(1, result.getSize());
    assertXMLEqual("Oops", xmldoc, result.getResource(0).getContent().toString());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 68 with XPathQueryService

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

the class XQueryTest method xupdateWithAdjacentTextNodes.

@Ignore
@Test
public void xupdateWithAdjacentTextNodes() throws XMLDBException {
    String query = "let $name := xmldb:store('/db' , 'xupdateTest.xml', <test>aaa</test>)" + "let $xu :=" + "<xu:modifications xmlns:xu='http://www.xmldb.org/xupdate' version='1.0'>" + "<xu:append select='/test'>" + "<xu:text>yyy</xu:text>" + "</xu:append>" + "</xu:modifications>" + "let $count := xmldb:update('/db' , $xu)" + "for $textNode in doc('/db/xupdateTest.xml')/test/text()" + "	return <text id='{util:node-id($textNode)}'>{$textNode}</text>";
    XPathQueryService service = storeXMLStringAndGetQueryService(NUMBERS_XML, numbers);
    ResourceSet result = service.query(query);
    assertEquals("XQuery: " + query, 1, result.getSize());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 69 with XPathQueryService

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

the class XQueryTest method cdataQuery.

@Test
public void cdataQuery() throws XMLDBException {
    ResourceSet result;
    String query;
    XMLResource resu;
    final String xml = "<root><node><![CDATA[world]]></node></root>";
    XPathQueryService service = storeXMLStringAndGetQueryService("cdata.xml", xml);
    service.setProperty(OutputKeys.INDENT, "no");
    query = "//text()";
    result = service.queryResource("cdata.xml", query);
    assertEquals(1, result.getSize());
    resu = (XMLResource) result.getResource(0);
    assertEquals("XQuery: " + query, "world", resu.getContent().toString());
    query = "//node/text()";
    result = service.queryResource("cdata.xml", query);
    assertEquals(1, result.getSize());
    resu = (XMLResource) result.getResource(0);
    assertEquals("XQuery: " + query, "world", resu.getContent().toString());
    query = "//node/node()";
    result = service.queryResource("cdata.xml", query);
    assertEquals(1, result.getSize());
    resu = (XMLResource) result.getResource(0);
    assertEquals("XQuery: " + query, "world", resu.getContent().toString());
    query = "/root[node = 'world']";
    result = service.queryResource("cdata.xml", query);
    assertEquals(1, result.getSize());
    // NOTE - no cdata-section-elements specified for XDM serialization
    resu = (XMLResource) result.getResource(0);
    assertEquals("XQuery: " + query, "<root><node>world</node></root>", resu.getContent().toString());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet) XMLResource(org.xmldb.api.modules.XMLResource)

Example 70 with XPathQueryService

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

the class XQueryTest method wrongInvalidTypeError_1787285.

/**
 * An exception occurred during query execution: XPTY0004: Invalid type for
 * variable $arg1. Expected xs:string, got xs:integer
 *
 * @see http://sourceforge.net/tracker/index.php?func=detail&aid=1787285&group_id=17691&atid=117691
 */
@Test
public void wrongInvalidTypeError_1787285() throws XMLDBException {
    String query = "let $arg1 as xs:string := \"A String\"" + "let $arg2 as xs:integer := 3 return $arg2";
    XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    ResourceSet result = service.query(query);
    assertEquals(1, result.getSize());
    assertEquals(query, "3", result.getResource(0).getContent().toString());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Aggregations

XPathQueryService (org.xmldb.api.modules.XPathQueryService)148 ResourceSet (org.xmldb.api.base.ResourceSet)123 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)92 XMLResource (org.xmldb.api.modules.XMLResource)60 Collection (org.xmldb.api.base.Collection)31 Test (org.junit.Test)22 Resource (org.xmldb.api.base.Resource)18 XMLDBException (org.xmldb.api.base.XMLDBException)14 EXistResource (org.exist.xmldb.EXistResource)10 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)9 XUpdateQueryService (org.xmldb.api.modules.XUpdateQueryService)8 IndexQueryService (org.exist.xmldb.IndexQueryService)6 IOException (java.io.IOException)3 ResourceIterator (org.xmldb.api.base.ResourceIterator)3 BinaryResource (org.xmldb.api.modules.BinaryResource)3 MalformedURLException (java.net.MalformedURLException)2 Path (java.nio.file.Path)2 Node (org.w3c.dom.Node)2 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1