use of org.xmldb.api.modules.XMLResource in project exist by eXist-db.
the class XQueryTest method attributeAxis.
@Test
public void attributeAxis() throws XMLDBException {
ResourceSet result;
String query;
XMLResource resu;
@SuppressWarnings("unused") String large = createXMLContentWithLargeString();
XPathQueryService service = storeXMLStringAndGetQueryService(file_name, xml);
query = "let $node := (<c id=\"OK\">b</c>)/descendant-or-self::*/attribute::id " + "return <a>{$node}</a>";
result = service.query(query);
resu = (XMLResource) result.getResource(0);
assertEquals("XQuery: " + query, "OK", ((Element) resu.getContentAsDOM()).getAttribute("id"));
}
use of org.xmldb.api.modules.XMLResource in project exist by eXist-db.
the class XQueryTest method whereClause.
@Test
public void whereClause() throws XMLDBException, IOException, SAXException {
ResourceSet result;
String query;
@SuppressWarnings("unused") XMLResource resu;
@SuppressWarnings("unused") boolean exceptionThrown;
@SuppressWarnings("unused") String message;
XPathQueryService service = storeXMLStringAndGetQueryService(NUMBERS_XML, numbers);
service.setProperty(OutputKeys.INDENT, "no");
query = "let $a := element node1 { " + "attribute id {'id'}, " + "element node1 {'1'}, " + "element node2 {'2'} " + "} " + "for $x in $a " + "where $x/@id eq 'id' " + "return $x";
result = service.queryResource(NUMBERS_XML, query);
assertEquals("XQuery: " + query, 1, result.getSize());
assertXMLEqual("<node1 id='id'><node1>1</node1><node2>2</node2></node1>", ((XMLResource) result.getResource(0)).getContent().toString());
}
use of org.xmldb.api.modules.XMLResource in project exist by eXist-db.
the class XPathQueryTest method attributes.
/**
* test simple queries involving attributes
*/
@Test
public void attributes() throws XMLDBException {
final String testDocument = "numbers.xml";
final XQueryService service = storeXMLStringAndGetQueryService(testDocument, numbers);
String query = "/test/item[ @id='1' ]";
ResourceSet result = service.queryResource(testDocument, query);
assertEquals("XPath: " + query, 1, result.getSize());
XMLResource resource = (XMLResource) result.getResource(0);
Node node = resource.getContentAsDOM();
if (node.getNodeType() == Node.DOCUMENT_NODE)
node = node.getFirstChild();
assertEquals("XPath: " + query, "item", node.getNodeName());
query = "/test/item [ @type='alphanum' ]";
result = service.queryResource(testDocument, query);
assertEquals("XPath: " + query, 1, result.getSize());
}
use of org.xmldb.api.modules.XMLResource in project exist by eXist-db.
the class XPathQueryTest method dates.
@Test
public void dates() throws XMLDBException {
final XQueryService service = storeXMLStringAndGetQueryService("numbers.xml", numbers);
String query = "xs:untypedAtomic(\"--12-05:00\") cast as xs:gMonth";
ResourceSet result = service.queryResource("numbers.xml", query);
XMLResource resource = (XMLResource) result.getResource(0);
assertEquals("XPath: " + query, "--12-05:00", resource.getContent().toString());
query = "(xs:dateTime(\"0001-01-01T01:01:01Z\") + xs:yearMonthDuration(\"-P20Y07M\"))";
result = service.queryResource("numbers.xml", query);
resource = (XMLResource) result.getResource(0);
assertEquals("XPath: " + query, "-0021-06-01T01:01:01Z", resource.getContent().toString());
}
use of org.xmldb.api.modules.XMLResource in project exist by eXist-db.
the class XPathQueryTest method last.
@Test
public void last() throws XMLDBException {
final XQueryService service = storeXMLStringAndGetQueryService("numbers.xml", numbers);
final String query = "<a><b>test1</b><b>test2</b></a>/b/last()";
final ResourceSet result = service.queryResource("numbers.xml", query);
assertEquals("XPath: " + query, 2, result.getSize());
XMLResource resource = (XMLResource) result.getResource(0);
assertEquals("XPath: " + query, "2", resource.getContent().toString());
resource = (XMLResource) result.getResource(1);
assertEquals("XPath: " + query, "2", resource.getContent().toString());
}
Aggregations