Search in sources :

Example 41 with XPathQueryService

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

the class XQueryTest method nameConflicts.

@Test
public void nameConflicts() throws XMLDBException {
    String query = "let $a := <name name=\"Test\"/> return <wrap>{$a//@name}</wrap>";
    XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    ResourceSet result = service.query(query);
    assertEquals(1, result.getSize());
    assertEquals("<wrap name=\"Test\"/>", 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 42 with XPathQueryService

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

the class XQueryTest method positionInPredicate.

@Test
public void positionInPredicate() throws XMLDBException {
    String query = "let $example := <Root> <Element>1</Element> <Element>2</Element> </Root>" + "return  $example/Element[1] ";
    XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    ResourceSet result = service.query(query);
    assertEquals("<Element>1</Element>", result.getResource(0).getContent().toString());
    query = "let $example := <Root> <Element>1</Element> <Element>2</Element> </Root>" + "return  $example/Element[position() = 1] ";
    result = service.query(query);
    assertEquals("<Element>1</Element>", 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 43 with XPathQueryService

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

the class XQueryTest method cardinalityAttributeNamespace_1884360.

/**
 * @see http://sourceforge.net/support/tracker.php?aid=1884360
 */
@Test
public void cardinalityAttributeNamespace_1884360() throws XMLDBException {
    String query = "let $el := <element a=\"1\" b=\"2\"/> " + "for $attr in $el/attribute()[namespace-uri(.) ne \"h\"] " + "return <c>{$attr}</c>";
    XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    ResourceSet result = service.query(query);
    assertEquals(2, result.getSize());
    assertEquals(query, "<c a=\"1\"/>", result.getResource(0).getContent().toString());
    assertEquals(query, "<c b=\"2\"/>", result.getResource(1).getContent().toString());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 44 with XPathQueryService

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

the class XQueryTest method elementConstructionWithNamespace_1740880.

/**
 * @see http://sourceforge.net/support/tracker.php?aid=1740880
 */
@Test
public void elementConstructionWithNamespace_1740880() throws XMLDBException {
    String query = "let $a := <foo:Bar xmlns:foo=\"urn:foo\"/> " + "let $b := element { QName(\"urn:foo\", \"foo:Bar\") } { () } " + "return deep-equal($a, $b) ";
    XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    ResourceSet result = service.query(query);
    assertEquals("Oops", "true", 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 45 with XPathQueryService

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

the class XQueryTest method largeAttributeText.

@Test
public void largeAttributeText() throws XMLDBException {
    final String large = "challengesininformationretrievalandlanguagemodelingreportofaworkshopheldatthecenterforintelligentinformationretrievaluniversityofmassachusettsamherstseptember2002-extdocid-howardturtlemarksandersonnorbertfuhralansmeatonjayaslamdragomirradevwesselkraaijellenvoorheesamitsinghaldonnaharmanjaypontejamiecallannicholasbelkinjohnlaffertylizliddyronirosenfeldvictorlavrenkodavidjharperrichschwartzjohnpragerchengxiangzhaijinxixusalimroukosstephenrobertsonandrewmccallumbrucecroftrmanmathasuedumaisdjoerdhiemstraeduardhovyralphweischedelthomashofmannjamesallanchrisbuckleyphilipresnikdavidlewis2003";
    String xml = "<details format='xml'><metadata docid='" + large + "'></metadata></details>";
    final String FILE_NAME = "detail_xml.xml";
    XPathQueryService service = storeXMLStringAndGetQueryService(FILE_NAME, xml);
    String query = "doc('" + FILE_NAME + "') / details/metadata[@docid= '" + large + "' ]";
    ResourceSet result = service.queryResource(FILE_NAME, query);
    assertEquals(1, result.getSize());
    xml = "<details format='xml'><metadata><docid>" + large + "</docid></metadata></details>";
    service = storeXMLStringAndGetQueryService(FILE_NAME, xml);
    query = "doc('" + FILE_NAME + "') / details/metadata[ docid= '" + large + "' ]";
    result = service.queryResource(FILE_NAME, query);
    assertEquals(1, result.getSize());
}
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