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