Package org.xmldb.api.modules

Examples of org.xmldb.api.modules.XQueryService


    @Test
    public void insertNamespacedAttribute() throws XMLDBException {

        final String docName = "pathNs2.xml";
        XQueryService service =
            storeXMLStringAndGetQueryService(docName, "<test/>");

        queryResource(service, docName, "//t[@xml:id]", 0);

        String update = "update insert <t xml:id=\"id1\"/> into /test";
View Full Code Here


public class UpdateValueTest extends AbstractTestUpdate {

    @Test
    public void updateNamespacedAttribute() throws XMLDBException {
        final String docName = "pathNs.xml";
        XQueryService service =
            storeXMLStringAndGetQueryService(docName, "<test><t xml:id=\"id1\"/></test>");

        queryResource(service, docName, "//t[@xml:id eq 'id1']", 1);

        queryResource(service, docName, "update value //t/@xml:id with 'id2'", 0);
View Full Code Here

    }
    }
   
   
    private String execQuery(String query) throws XMLDBException {
      XQueryService service = (XQueryService) testCollection.getService("XQueryService", "1.0");
        service.setProperty("indent", "no");
      ResourceSet result = service.query(query);
      assertEquals(result.getSize(), 1);
      return result.getResource(0).getContent().toString();
    }
View Full Code Here

            doc.setContent(module6);
            ((EXistResource) doc).setMimeType("application/xquery");
            testCollection.storeResource(doc);

            System.out.println("testGlobalVars 1: ========");
            XQueryService service = (XQueryService) testCollection.getService("XPathQueryService", "1.0");
            String query = "xquery version \"1.0\";\n" + "import module namespace foo=\"foo\" at \"" + URI + "/test/" + MODULE5_NAME + "\";\n" + "$foo:bar";
            ResourceSet result = service.query(query);
            assertEquals(result.getSize(), 1);
            assertEquals(result.getResource(0).getContent(), "bar");

            System.out.println("testGlobalVars 2: ========");
            query = "xquery version \"1.0\";\n" + "declare variable $local:a := 'abc';" + "$local:a";
            result = service.query(query);
            assertEquals(result.getSize(), 1);
            assertEquals(result.getResource(0).getContent(), "abc");

            System.out.println("testGlobalVars 3: ========");
            boolean gotException = false;
            try {
                query = "xquery version \"1.0\";\n" + "import module namespace foo=\"foo\" at \"" + URI + "/test/" + MODULE6_NAME + "\";\n" + "$foo:bar";
                result = service.query(query);
            } catch (XMLDBException e) {
                assertTrue("Test should generate err:XQST0049, got: " + e.getMessage(), e.getMessage().indexOf("err:XQST0049") > -1);
                gotException = true;
            }
            assertTrue("Duplicate global variable should generate error", gotException);

            System.out.println("testGlobalVars 4: ========");
            gotException = false;
            try {
                query = "xquery version \"1.0\";\n" + "declare variable $local:a := 'abc';" + "declare variable $local:a := 'abc';" + "$local:a";
                result = service.query(query);
            } catch (XMLDBException e) {
                assertTrue("Test should generate err:XQST0049, got: " + e.getMessage(), e.getMessage().indexOf("err:XQST0049") > -1);
                gotException = true;
            }
            assertTrue("Duplicate global variable should generate error", gotException);
View Full Code Here

        "return ( " +
          "update replace $link with \"123\", " +
          "(: without the output on the next line, it works :) " +
          "xs:string($link) " +
        ")";
        XQueryService service = (XQueryService) testCollection.getService("XQueryService", "1.0");
        ResourceSet r = service.query(query);
        assertEquals(r.getSize(), 2);       
      assertEquals(r.getResource(0).getContent().toString(), "123");
      assertEquals(r.getResource(1).getContent().toString(), "123");
    } catch (XMLDBException e) {
      e.printStackTrace();
View Full Code Here

        }

    }
   
    private String execQuery(String query) throws XMLDBException {
      XQueryService service = (XQueryService) testCollection.getService("XQueryService", "1.0");
      ResourceSet result = service.query(query);
      assertEquals(result.getSize(), 1);
      return result.getResource(0).getContent().toString();
    }
View Full Code Here

    /**
     * Add attribute to element which already has an attribute of that name.
     */
    @Test (expected=XMLDBException.class)
    public void appendStoredAttrFail() throws XMLDBException {
        XQueryService xqs = (XQueryService) testCollection.getService("XQueryService", "1.0");
        String query =
            "let $a := \n" +
            "<node attr=\"a\" b=\"c\">{doc(\"/db/test/stored1.xml\")//@attr}</node>" +
            "return $a";
        xqs.query(query);
    }
View Full Code Here

     * Add attribute to element which has no conflicting attributes.
     */
    @Test
    public void appendStoredAttrOK() {
        try {
            XQueryService xqs = (XQueryService) testCollection.getService("XQueryService", "1.0");
            String query =
                "let $a := \n" +
                "<node attr=\"a\" b=\"c\">{doc(\"/db/test/stored2.xml\")//@attr2}</node>" +
                "return $a";
            ResourceSet result = xqs.query(query);
            assertEquals(1, result.getSize());
            assertEquals("<node attr=\"a\" b=\"c\" attr2=\"ab\"/>", result.getResource(0).getContent());
        } catch (XMLDBException e) {
            e.printStackTrace();
            fail(e.getMessage());
View Full Code Here

     * Add constructed in-memory attribute to element which already has an
     * attribute of that name.
     */
    @Test (expected=XMLDBException.class)
    public void appendConstrAttr() throws XMLDBException {
        XQueryService xqs = (XQueryService) testCollection.getService("XQueryService", "1.0");
        String query =
            "let $a := <root attr=\"ab\"/>" +
            "let $b := \n" +
            "   <node attr=\"a\" b=\"c\">{$a//@attr}</node>" +
            "return $a";
        xqs.query(query);
    }
View Full Code Here

     * Add attribute to element which already has an
     * attribute of that name (using idref).
     */
    @Test (expected=XMLDBException.class)
    public void appendIdref() throws XMLDBException {
        XQueryService xqs = (XQueryService) testCollection.getService("XQueryService", "1.0");
        String query =
            "<results>{fn:idref(('id1', 'id2'), doc('/db/test/docdtd.xml')/IDS)}</results>";
        ResourceSet result = xqs.query(query);
        System.out.println(result.getResource(0).getContent());
    }
View Full Code Here

TOP

Related Classes of org.xmldb.api.modules.XQueryService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.