zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #15472
[Merge] lp:~zorba-coders/zorba/xqxq-url-resolver into lp:zorba/xqxq-module
Chris Hillery has proposed merging lp:~zorba-coders/zorba/xqxq-url-resolver into lp:zorba/xqxq-module.
Commit message:
Bug 903797: add feature to prepare-main-module() to enable URI mappers and URL resolvers written in XQuery.
Requested reviews:
Chris Hillery (ceejatec)
Matthias Brantner (matthias-brantner)
Sorin Marian Nasoi (sorin.marian.nasoi)
Related bugs:
Bug #903797 in Zorba: "XQXQ feature request: custom schema uri resolver"
https://bugs.launchpad.net/zorba/+bug/903797
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/xqxq-url-resolver/+merge/130460
--
https://code.launchpad.net/~zorba-coders/zorba/xqxq-url-resolver/+merge/130460
Your team Zorba Coders is subscribed to branch lp:zorba/xqxq-module.
=== modified file 'src/xqxq.xq'
--- src/xqxq.xq 2012-09-28 13:48:30 +0000
+++ src/xqxq.xq 2012-10-19 01:17:21 +0000
@@ -26,9 +26,12 @@
module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
declare namespace an = "http://www.zorba-xquery.com/annotations";
-
declare namespace ver = "http://www.zorba-xquery.com/options/versioning";
+declare namespace op = "http://www.zorba-xquery.com/options/features";
+declare namespace f = "http://www.zorba-xquery.com/features";
+
declare option ver:module-version "1.0";
+declare option op:enable "f:hof";
(:~
: The function prepares a given XQuery program for execution.
@@ -56,6 +59,106 @@
xs:anyURI external;
(:~
+ : The function prepares a given XQuery program for execution.
+ : If the program was successfully compiled, the function returns an
+ : identifier as xs:anyURI. This URI can be passed to other functions
+ : of this module (e.g. to actually evaluate the program). The URI
+ : is opaque and its lilfetime is bound by the lifetime of the XQuery
+ : program that invoked this function. Further reference or uses
+ : of the identifier lead to unexpected results.
+ :
+ : Important notes regarding the second and third parameters of the function:
+ : --------------------------------------------------------------------------
+ :
+ : These parameters allow you to specify a URL resolver and a URI mapper
+ : for Zorba to use when executing this query. See
+ : http://www.zorba-xquery.com/html/documentation/2.7.0/zorba/uriresolvers
+ :
+ : The second parameter is a function item for a URL
+ : resolver. The URL resolver function must recive 2 parameters:
+ : A $namespace as xs:string that will contain the url to be resolved.
+ : A $entity as xs:string that will contain the type of resolving needed;
+ : this can be 2 values "module" and "schema".
+ : The function must return an empty sequence when the specified $namespace
+ : or $entity are not the ones to be resolved.
+ :
+ : Example:
+ :
+ : declare function mymod:url-resolver($namespace as xs:string, $entity as xs:string)
+ : {
+ : if($namespace = 'http://test.xq')
+ : then "module namespace test = 'http://test'; declare function test:foo(){'foo'};"
+ : else ()
+ : };
+ :
+ : The URL resolver function's namespace, name, and parameter naming are
+ : not restricted by XQXQ.
+ :
+ : The URL resolver function's return type is not restricted, it could be a string, a sequence,
+ : a node, etc. All the outputs types are to be serialized as a string.
+ :
+ : The third parameter is a function item for a URI mapper.
+ : The URI mapper function, just like the URL resolver, receives 2 parameters:
+ : A $namespace as xs:string that will contain the URI to be mapped.
+ : A $entity as xs:string that will contain the type of resolving needed;
+ : this can be 2 values "module" and "schema".
+ : The URI mapper must return an empty sequence when the specified $namesapce or $entity
+ : are not to be mapped. Unlike the URL resolver this function must return a sequence of strings.
+ :
+ : Example:
+ :
+ : declare function mymod:uri-mapper($namespace as xs:string, $entity as xs:string)
+ : {
+ : if($namespace = 'http://test')
+ : then ("http://www.zorba-xquery.com/test", "http://foo.com/schema/test")
+ : else ()
+ : };
+ :
+ : The URI mapper function's namespace, name, and parameter naming are
+ : not restricted by XQXQ.
+ :
+ : In order to pass the above URL resolver and URI mapper to this function,
+ : use the following syntax:
+ :
+ : variable $queryID := xqxq:prepare-main-module("..query text..",
+ : mymod:url-resolver#2, mymod:uri-mapper#2);
+ :
+ : That is, the QName of the function followed by "#2". This is XQuery
+ : "higher-order function" syntax, meaning the function with the specified
+ : QName which takes two arguments. Since URL resolvers and URI mappers
+ : must take two arguments, both will always be specified with "#2".
+ :
+ : Note that parameters 2 and 3 should be declared as follows:
+ : as function($url as xs:string, $entity as xs:string) as item()
+ : as function($uri as xs:string, $entity as xs:string) as xs:string*
+ : However Zorba's implementation of higher-order functions (HOF) is not
+ : yet complete enough to allow for this. When Zorba's HOF implementation
+ : is complete this function signature will be changed.
+ :
+ : Both the URL resolver and URI mapper functions are optional, meaning you
+ : may pass the empty-sequence () for either.
+ :
+ : Successfully prepared queries need to be deleted by passing the resulting
+ : identifier to the xqxq:delete-query function of this module.
+ :
+ : @param $main-module-text the XQuery program that should be prepared.
+ : The program needs to be a XQuery main module.
+ :
+ : @param $resolver the URL resolver function.
+ :
+ : @param $mapper the URI mapper function.
+ :
+ : @return an identifier for the compiled program that can be passed
+ : as arguments to other functions of this module.
+ :
+ : @error any (static or type) error that may be raised during the compilation
+ : of the query. For example, err:XPST0003 if the given XQuery program could
+ : not be parsed.
+ :)
+declare %an:sequential function xqxq:prepare-main-module($main-module-text as xs:string, $resolver as item()?, $mapper as item()?) as
+ xs:anyURI external;
+
+(:~
: This function compiles a given XQuery library module. It can be used
: to compile-check a module.
:
@@ -265,3 +368,14 @@
:)
declare %an:sequential function xqxq:delete-query($query-key as xs:anyURI) as
empty-sequence() external;
+
+
+(:~
+ : Internal helper function. Only necessary because of incomplete HOF
+ : support in Zorba.
+ :)
+declare %private function xqxq:hof-invoker($hof as item(),
+ $ns as xs:string, $entity as xs:string) as item()*
+{
+ $hof($ns, $entity)
+};
=== modified file 'src/xqxq.xq.src/xqxq.cpp'
--- src/xqxq.xq.src/xqxq.cpp 2012-10-01 17:54:38 +0000
+++ src/xqxq.xq.src/xqxq.cpp 2012-10-19 01:17:21 +0000
@@ -226,6 +226,131 @@
/*******************************************************************************************
*******************************************************************************************/
+ static void streamReleaser(std::istream* aStream)
+ {
+ delete aStream;
+ }
+
+ void
+ PrepareMainModuleFunction::XQXQURIMapper::mapURI(
+ String aUri,
+ EntityData const* aEntityData,
+ std::vector<String>& oUris)
+ {
+ //Create entityData string to send to the new url resolver
+ String lDataKind;
+ switch (aEntityData->getKind())
+ {
+ case EntityData::SCHEMA:
+ lDataKind = "schema";
+ break;
+ case EntityData::MODULE:
+ lDataKind = "module";
+ break;
+ default:
+ break;
+ }
+
+ //construct the arguments for the url resolver
+ std::vector<ItemSequence_t> lArgs;
+ ItemSequence_t lSeq0 = new SingletonItemSequence(theFunction);
+ ItemSequence_t lSeq1 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(aUri));
+ ItemSequence_t lSeq2 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(lDataKind));
+ lArgs.push_back(lSeq0);
+ lArgs.push_back(lSeq1);
+ lArgs.push_back(lSeq2);
+
+ //invoke the HOF helper function using the arguments generated
+ Item lHofHelper = XQXQModule::getItemFactory()->createQName("http://www.zorba-xquery.com/modules/xqxq", "xqxq", "hof-invoker");
+ ItemSequence_t lResult = theCtx->invoke(lHofHelper, lArgs);
+
+ //Check if the result is an empty sequence by creating an Iterator, this is cheaper than serializing the result
+ //and then checking if it was empty.
+ Iterator_t lIter = lResult->getIterator();
+ Item lItem;
+ lIter->open();
+ while (lIter->next(lItem))
+ {
+ std::cout << lItem.getStringValue() << std::endl;
+ oUris.push_back(lItem.getStringValue());
+ }
+ lIter->close();
+
+ }
+
+
+ Resource*
+ PrepareMainModuleFunction::XQXQURLResolver::resolveURL(
+ const String& aUrl,
+ EntityData const* aEntityData)
+ {
+ //Create entityData string to send to the new url resolver
+ String lDataKind;
+ switch (aEntityData->getKind())
+ {
+ case EntityData::SCHEMA:
+ lDataKind = "schema";
+ break;
+ case EntityData::MODULE:
+ lDataKind = "module";
+ break;
+ default:
+ break;
+ }
+
+ //construct the arguments for the url resolver
+ std::vector<ItemSequence_t> lArgs;
+ ItemSequence_t lSeq0 = new SingletonItemSequence(theFunction);
+ ItemSequence_t lSeq1 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(aUrl));
+ ItemSequence_t lSeq2 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(lDataKind));
+ lArgs.push_back(lSeq0);
+ lArgs.push_back(lSeq1);
+ lArgs.push_back(lSeq2);
+
+ //invoke the HOF helper function using the arguments generated
+ Item lHofHelper = XQXQModule::getItemFactory()->createQName("http://www.zorba-xquery.com/modules/xqxq", "xqxq", "hof-invoker");
+ ItemSequence_t lResult = theCtx->invoke(lHofHelper, lArgs);
+
+ //Check if the result is an empty sequence by creating an Iterator, this is cheaper than serializing the result
+ //and then checking if it was empty.
+ Iterator_t lIter = lResult->getIterator();
+ Item lItem;
+ lIter->open();
+ lIter->next(lItem);
+ lIter->close();
+ if (lItem.isNull())
+ return NULL;
+
+ //Serialize resulting sequence of the resolver
+ Zorba_SerializerOptions_t lOpt;
+ if (lItem.isNode())
+ lOpt.ser_method = ZORBA_SERIALIZATION_METHOD_XML;
+ else
+ lOpt.ser_method = ZORBA_SERIALIZATION_METHOD_TEXT;
+ lOpt.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES;
+ Serializer_t lSer = Serializer::createSerializer(lOpt);
+ std::stringstream lSerResult;
+ lSer->serialize(lResult, lSerResult);
+
+ //return resource
+ return StreamResource::create(new std::istringstream(lSerResult.str()), &streamReleaser);
+
+ /*
+ // we have only one module
+ if (aEntityData->getKind() == EntityData::MODULE &&
+ aUrl == "http://www.zorba-xquery.com/modules/xqxq/test")
+ {
+ return StreamResource::create
+ (new std::istringstream
+ ("module namespace test = 'http://www.zorba-xquery.com/modules/xqxq/test'; "
+ "declare function test:foo() { 'foo' };"), &streamReleaser);
+ }
+ else {
+ return NULL;
+ }
+ */
+ }
+
zorba::ItemSequence_t
PrepareMainModuleFunction::evaluate(
const Arguments_t& aArgs,
@@ -233,6 +358,8 @@
const zorba::DynamicContext* aDctx) const
{
DynamicContext* lDynCtx = const_cast<DynamicContext*>(aDctx);
+ StaticContext_t lSctxChild = aSctx->createChildContext();
+ StaticContext_t lMapperSctx = aSctx->createChildContext();
QueryMap* lQueryMap;
if(!(lQueryMap = dynamic_cast<QueryMap*>(lDynCtx->getExternalFunctionParameter("xqxqQueryMap"))))
@@ -247,9 +374,34 @@
XQuery_t lQuery;
+ StaticContext_t ltempSctx = lZorba->createStaticContext();
+ XQXQURLResolver* lResolver = NULL;
+ XQXQURIMapper* lMapper = NULL;
+
+ if ( aArgs.size() > 2 )
+ {
+ Item lMapperFunctionItem = getItemArgument(aArgs, 2);
+ if (!lMapperFunctionItem.isNull())
+ {
+ lMapper = new XQXQURIMapper(lMapperFunctionItem, lSctxChild);
+ ltempSctx->registerURIMapper(lMapper);
+ }
+ }
+
+ if ( aArgs.size() > 1 )
+ {
+ Item lResolverFunctionItem = getItemArgument(aArgs, 1);
+ if (!lResolverFunctionItem.isNull())
+ {
+ lResolver = new XQXQURLResolver(lResolverFunctionItem, lSctxChild);
+ ltempSctx->registerURLResolver(lResolver);
+ }
+
+ }
+
try
{
- lQuery = lZorba->compileQuery(lQueryString);
+ lQuery = lZorba->compileQuery(lQueryString, ltempSctx);
}
catch (XQueryException& xe)
{
@@ -277,12 +429,18 @@
lStream << lUUID;
String lStrUUID = lStream.str();
+
+ lQueryMap->storeQuery(lStrUUID, lQuery);
- lQueryMap->storeQuery(lStrUUID, lQuery);
+ if (lResolver)
+ delete lResolver;
+ if (lMapper)
+ delete lMapper;
return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createAnyURI(lStrUUID)));
}
+
/*******************************************************************************************
*******************************************************************************************/
zorba::ItemSequence_t
=== modified file 'src/xqxq.xq.src/xqxq.h'
--- src/xqxq.xq.src/xqxq.h 2012-10-01 17:54:38 +0000
+++ src/xqxq.xq.src/xqxq.h 2012-10-19 01:17:21 +0000
@@ -49,6 +49,7 @@
};
+
class QueryMap : public ExternalFunctionParameter{
private:
typedef std::map<String, XQuery_t> QueryMap_t;
@@ -117,7 +118,7 @@
public:
PrepareMainModuleFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
- virtual ~PrepareMainModuleFunction(){}
+ virtual ~PrepareMainModuleFunction(){ }
virtual zorba::String
getLocalName() const { return "prepare-main-module"; }
@@ -126,6 +127,43 @@
evaluate(const Arguments_t&,
const zorba::StaticContext*,
const zorba::DynamicContext*) const;
+
+ protected:
+
+ class XQXQURLResolver : public URLResolver
+ {
+ protected:
+ Item theFunction;
+ StaticContext_t theCtx;
+
+ public:
+ XQXQURLResolver(Item& aFunction, StaticContext_t& aSctx) : URLResolver(), theFunction(aFunction), theCtx(aSctx) {}
+
+ virtual ~XQXQURLResolver(){ }
+
+ virtual Resource* resolveURL(const String& aUrl,
+ EntityData const* aEntityData);
+
+ };
+
+ class XQXQURIMapper : public URIMapper
+ {
+ protected:
+ Item theFunction;
+ StaticContext_t theCtx;
+
+ public:
+ XQXQURIMapper(Item& aFunction, StaticContext_t& aSctx) : URIMapper(), theFunction(aFunction), theCtx(aSctx) {}
+
+ virtual ~XQXQURIMapper(){ }
+
+ virtual void mapURI(
+ const zorba::String aUri,
+ EntityData const* aEntityData,
+ std::vector<zorba::String>& oUris);
+
+ };
+
};
class PrepareLibraryModuleFunction : public XQXQFunction{
=== added file 'test/ExpQueryResults/xqxq/uri-mapper.xml.res'
--- test/ExpQueryResults/xqxq/uri-mapper.xml.res 1970-01-01 00:00:00 +0000
+++ test/ExpQueryResults/xqxq/uri-mapper.xml.res 2012-10-19 01:17:21 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+foo
=== added file 'test/ExpQueryResults/xqxq/uri-mapper2.xml.res'
--- test/ExpQueryResults/xqxq/uri-mapper2.xml.res 1970-01-01 00:00:00 +0000
+++ test/ExpQueryResults/xqxq/uri-mapper2.xml.res 2012-10-19 01:17:21 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test:test xmlns:test="http://test"><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>
=== added file 'test/ExpQueryResults/xqxq/url-module-resolver.xml.res'
--- test/ExpQueryResults/xqxq/url-module-resolver.xml.res 1970-01-01 00:00:00 +0000
+++ test/ExpQueryResults/xqxq/url-module-resolver.xml.res 2012-10-19 01:17:21 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+foo
=== added file 'test/ExpQueryResults/xqxq/url-schema-resolver.xml.res'
--- test/ExpQueryResults/xqxq/url-schema-resolver.xml.res 1970-01-01 00:00:00 +0000
+++ test/ExpQueryResults/xqxq/url-schema-resolver.xml.res 2012-10-19 01:17:21 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test:test xmlns:test="http://test"><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>
=== added file 'test/ExpQueryResults/xqxq/url-schema-resolver2.xml.res'
--- test/ExpQueryResults/xqxq/url-schema-resolver2.xml.res 1970-01-01 00:00:00 +0000
+++ test/ExpQueryResults/xqxq/url-schema-resolver2.xml.res 2012-10-19 01:17:21 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test:test xmlns:test="http://test"><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>
=== added file 'test/Queries/xqxq/test.xsd'
--- test/Queries/xqxq/test.xsd 1970-01-01 00:00:00 +0000
+++ test/Queries/xqxq/test.xsd 2012-10-19 01:17:21 +0000
@@ -0,0 +1,14 @@
+<?xml version="1.0"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://test"
+ xmlns="http://test"
+ elementFormDefault="qualified">
+ <xs:element name="test">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="subtest" type="xs:string"/>
+ <xs:element name="subtest2" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+</xs:schema>
\ No newline at end of file
=== added file 'test/Queries/xqxq/uri-mapper.xq'
--- test/Queries/xqxq/uri-mapper.xq 1970-01-01 00:00:00 +0000
+++ test/Queries/xqxq/uri-mapper.xq 2012-10-19 01:17:21 +0000
@@ -0,0 +1,27 @@
+import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
+
+declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';
+declare namespace mapper = 'http://www.zorba-xquery.com/modules/xqxq/uri-mapper';
+declare namespace op = "http://www.zorba-xquery.com/options/features";
+declare namespace f = "http://www.zorba-xquery.com/features";
+declare option op:enable "f:hof";
+
+declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
+ if($namespace = 'http://foo')
+ then "module namespace test = 'http://test'; declare function test:foo(){'foo'};"
+ else ()
+};
+
+declare function mapper:uri-mapper($namespace as xs:string, $entity as xs:string)
+{
+ if($namespace = 'http://test')
+ then 'http://foo'
+ else ()
+};
+
+variable $queryID := xqxq:prepare-main-module
+(
+ "import module namespace test = 'http://test'; test:foo()",
+ resolver:url-resolver#2, mapper:uri-mapper#2
+);
+xqxq:evaluate($queryID)
=== added file 'test/Queries/xqxq/uri-mapper2.xq'
--- test/Queries/xqxq/uri-mapper2.xq 1970-01-01 00:00:00 +0000
+++ test/Queries/xqxq/uri-mapper2.xq 2012-10-19 01:17:21 +0000
@@ -0,0 +1,22 @@
+import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
+
+declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';
+declare namespace mapper = 'http://www.zorba-xquery.com/modules/xqxq/uri-mapper';
+declare namespace op = "http://www.zorba-xquery.com/options/features";
+declare namespace f = "http://www.zorba-xquery.com/features";
+declare option op:enable "f:hof";
+
+declare function mapper:uri-mapper($namespace as xs:string, $entity as xs:string)
+{
+ if ($namespace = 'http://test' and $entity = 'schema')
+ then resolve-uri('test.xsd')
+ else ()
+};
+
+variable $queryID := xqxq:prepare-main-module
+(
+ "import schema namespace test = 'http://test'; validate{<test:test><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>}",
+ (),
+ mapper:uri-mapper#2
+);
+xqxq:evaluate($queryID)
=== added file 'test/Queries/xqxq/url-module-resolver.xq'
--- test/Queries/xqxq/url-module-resolver.xq 1970-01-01 00:00:00 +0000
+++ test/Queries/xqxq/url-module-resolver.xq 2012-10-19 01:17:21 +0000
@@ -0,0 +1,17 @@
+import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
+
+declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';
+declare namespace op = "http://www.zorba-xquery.com/options/features";
+declare namespace f = "http://www.zorba-xquery.com/features";
+declare option op:enable "f:hof";
+
+declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
+ if($namespace = 'http://test.xq')
+ then "module namespace test = 'http://test'; declare function test:foo(){'foo'};"
+ else ()
+};
+
+variable $queryID := xqxq:prepare-main-module(
+ "import module namespace test = 'http://test'; test:foo()",
+ resolver:url-resolver#2, ());
+xqxq:evaluate($queryID)
=== added file 'test/Queries/xqxq/url-schema-resolver.xq'
--- test/Queries/xqxq/url-schema-resolver.xq 1970-01-01 00:00:00 +0000
+++ test/Queries/xqxq/url-schema-resolver.xq 2012-10-19 01:17:21 +0000
@@ -0,0 +1,20 @@
+import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
+
+declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';
+
+declare namespace op = "http://www.zorba-xquery.com/options/features";
+declare namespace f = "http://www.zorba-xquery.com/features";
+declare option op:enable "f:hof";
+
+declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
+ if($namespace = 'http://test' and $entity = 'schema')
+ then
+ doc('test.xsd')
+ else
+ ()
+};
+
+variable $queryID := xqxq:prepare-main-module(
+ "import schema namespace test = 'http://test'; validate {<test:test><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>}",
+ resolver:url-resolver#2, ());
+xqxq:evaluate($queryID)
=== added file 'test/Queries/xqxq/url-schema-resolver2.xq'
--- test/Queries/xqxq/url-schema-resolver2.xq 1970-01-01 00:00:00 +0000
+++ test/Queries/xqxq/url-schema-resolver2.xq 2012-10-19 01:17:21 +0000
@@ -0,0 +1,29 @@
+import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
+
+import module namespace ddl =
+ "http://www.zorba-xquery.com/modules/store/dynamic/collections/w3c/ddl";
+import module namespace dml =
+ "http://www.zorba-xquery.com/modules/store/dynamic/collections/w3c/dml";
+
+declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';
+declare namespace op = "http://www.zorba-xquery.com/options/features";
+declare namespace f = "http://www.zorba-xquery.com/features";
+declare option op:enable "f:hof";
+
+declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
+ if ($entity = 'schema')
+ then
+ dml:collection("http://www.zorba-xquery.com/modules/xqxq")//xs:schema[@targetNamespace=$namespace]
+ else
+ ()
+};
+
+declare variable $coll := "http://www.zorba-xquery.com/modules/xqxq";
+declare variable $schema := doc("test.xsd");
+ddl:create($coll);
+
+dml:apply-insert-nodes-first($coll, $schema);
+variable $query-key := xqxq:prepare-main-module(
+ "import schema namespace test = 'http://test'; validate {<test:test><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>}",
+ resolver:url-resolver#2, ());
+xqxq:evaluate($query-key)
Follow ups
-
[Merge] lp:~zorba-coders/zorba/xqxq-url-resolver into lp:zorba/xqxq-module
From: noreply, 2012-10-19
-
[Merge] lp:~zorba-coders/zorba/xqxq-url-resolver into lp:zorba/xqxq-module
From: Zorba Build Bot, 2012-10-19
-
[Merge] lp:~zorba-coders/zorba/xqxq-url-resolver into lp:zorba/xqxq-module
From: Zorba Build Bot, 2012-10-19
-
[Merge] lp:~zorba-coders/zorba/xqxq-url-resolver into lp:zorba/xqxq-module
From: Sorin Marian Nasoi, 2012-10-19
-
Re: [Merge] lp:~zorba-coders/zorba/xqxq-url-resolver into lp:zorba/xqxq-module
From: Sorin Marian Nasoi, 2012-10-19
-
Re: [Merge] lp:~zorba-coders/zorba/xqxq-url-resolver into lp:zorba/xqxq-module
From: Matthias Brantner, 2012-10-19
-
[Merge] lp:~zorba-coders/zorba/xqxq-url-resolver into lp:zorba/xqxq-module
From: Zorba Build Bot, 2012-10-19
-
Re: [Merge] lp:~zorba-coders/zorba/xqxq-url-resolver into lp:zorba/xqxq-module
From: Zorba Build Bot, 2012-10-19
-
[Merge] lp:~zorba-coders/zorba/xqxq-url-resolver into lp:zorba/xqxq-module
From: Zorba Build Bot, 2012-10-19
-
[Merge] lp:~zorba-coders/zorba/xqxq-url-resolver into lp:zorba/xqxq-module
From: Zorba Build Bot, 2012-10-19
-
[Merge] lp:~zorba-coders/zorba/xqxq-url-resolver into lp:zorba/xqxq-module
From: Chris Hillery, 2012-10-19
-
Re: [Merge] lp:~zorba-coders/zorba/xqxq-url-resolver into lp:zorba/xqxq-module
From: Chris Hillery, 2012-10-19
-
[Merge] lp:~zorba-coders/zorba/xqxq-url-resolver into lp:zorba/xqxq-module
From: Chris Hillery, 2012-10-19