use of org.xmldb.api.modules.XMLResource in project exist by eXist-db.
the class XQueryTest method largeAttributeSimple.
@Test
public void largeAttributeSimple() throws XMLDBException {
ResourceSet result;
String query;
@SuppressWarnings("unused") XMLResource resu;
String large = createXMLContentWithLargeString();
XPathQueryService service = storeXMLStringAndGetQueryService(file_name, xml);
query = "doc('" + file_name + "') / details/metadata[@docid= '" + large + "' ]";
result = service.queryResource(file_name, query);
assertEquals("XQuery: " + query, nbElem, result.getSize());
}
use of org.xmldb.api.modules.XMLResource in project exist by eXist-db.
the class XQueryTest method cdataSerialization.
@Test
public void cdataSerialization() throws XMLDBException {
ResourceSet result;
String query;
XMLResource resu;
XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
query = "let $doc := document{ <root><![CDATA[gaga]]></root> } " + "return $doc/root/string()";
result = service.query(query);
resu = (XMLResource) result.getResource(0);
assertEquals("XQuery: " + query, "gaga", resu.getContent().toString());
}
use of org.xmldb.api.modules.XMLResource in project exist by eXist-db.
the class XQueryTest method storeXMLStringAndGetQueryService.
// ======================================
/**
* @return
* @throws XMLDBException
*/
private XPathQueryService storeXMLStringAndGetQueryService(String documentName, String content) throws XMLDBException {
Collection testCollection = getTestCollection();
XMLResource doc = (XMLResource) testCollection.createResource(documentName, "XMLResource");
doc.setContent(content);
testCollection.storeResource(doc);
XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
return service;
}
use of org.xmldb.api.modules.XMLResource in project exist by eXist-db.
the class XQueryTest method variable.
@Test
public void variable() throws XMLDBException {
ResourceSet result;
String query;
XMLResource resu;
@SuppressWarnings("unused") boolean exceptionThrown;
String message;
XPathQueryService service = storeXMLStringAndGetQueryService(NUMBERS_XML, numbers);
query = "xquery version \"1.0\";\n" + "declare namespace param=\"param\";\n" + "declare variable $param:a {\"a\"};\n" + "declare function param:a() {$param:a};\n" + "let $param:a := \"b\" \n" + "return ($param:a, $param:a)";
result = service.query(query);
assertEquals("XQuery: " + query, 2, result.getSize());
assertEquals("XQuery: " + query, "b", ((XMLResource) result.getResource(0)).getContent());
assertEquals("XQuery: " + query, "b", ((XMLResource) result.getResource(1)).getContent());
query = "xquery version \"1.0\";\n" + "declare namespace param=\"param\";\n" + "declare variable $param:a {\"a\"};\n" + "declare function param:a() {$param:a};\n" + "let $param:a := \"b\" \n" + "return param:a(), param:a()";
result = service.query(query);
assertEquals("XQuery: " + query, 2, result.getSize());
assertEquals("XQuery: " + query, "a", ((XMLResource) result.getResource(0)).getContent());
assertEquals("XQuery: " + query, "a", ((XMLResource) result.getResource(1)).getContent());
query = "declare variable $foo {\"foo1\"};\n" + "let $foo := \"foo2\" \n" + "for $bar in (1 to 1) \n" + " let $foo := \"foo3\" \n" + " return $foo";
result = service.query(query);
assertEquals("XQuery: " + query, 1, result.getSize());
assertEquals("XQuery: " + query, "foo3", ((XMLResource) result.getResource(0)).getContent());
try {
message = "";
query = "xquery version \"1.0\";\n" + "declare variable $a {\"1st instance\"};\n" + "declare variable $a {\"2nd instance\"};\n" + "$a";
result = service.query(query);
} catch (XMLDBException e) {
message = e.getMessage();
}
assertTrue(message.indexOf("XQST0049") > -1);
query = "xquery version \"1.0\";\n" + "declare namespace param=\"param\";\n" + "declare function param:f() { $param:a };\n" + "declare variable $param:a {\"a\"};\n" + "param:f()";
result = service.query(query);
assertEquals("XQuery: " + query, 1, result.getSize());
assertEquals("XQuery: " + query, "a", ((XMLResource) result.getResource(0)).getContent());
query = "let $a := <root> " + "<b name='1'>" + " <c name='x'> " + " <bar name='2'/> " + " <bar name='3'> " + " <bar name='4'/> " + " </bar> " + " </c> " + "</b> " + "</root> " + "let $b := for $bar in $a/b/c/bar " + "where ($bar/../@name = 'x') " + "return $bar " + "return $b";
result = service.queryResource(NUMBERS_XML, query);
assertEquals("XQuery: " + query, 2, result.getSize());
resu = (XMLResource) result.getResource(0);
assertEquals("XQuery: " + query, "2", ((Element) resu.getContentAsDOM()).getAttribute("name"));
resu = (XMLResource) result.getResource(1);
assertEquals("XQuery: " + query, "3", ((Element) resu.getContentAsDOM()).getAttribute("name"));
}
use of org.xmldb.api.modules.XMLResource in project exist by eXist-db.
the class XQueryTest method retrieveLargeAttribute.
@Test
public void retrieveLargeAttribute() throws XMLDBException {
createXMLContentWithLargeString();
storeXMLStringAndGetQueryService(file_name, xml);
final XMLResource res = (XMLResource) getTestCollection().getResource(file_name);
assertTrue(res != null);
}
Aggregations