Support for data URIs in XQuery with Saxon in oXygen
Posted: Sun Aug 19, 2018 9:37 pm
To find out whether I can use XQuery that generates XQuery code and load/run it with the W3C standard function https://www.w3.org/TR/xpath-functions/# ... ery-module I tested whether I can use data URIs https://en.wikipedia.org/wiki/Data_URI_scheme inside of XQuery or XSLT.
To my surprise the following works with an XQuery Saxon 9.8.0.12 (tried EE and HE) transformation scenario in oXygen 20.1:
and returns
so it seems Saxon inside of oXygen has support for data URIs.
That is a surprise as running Saxon 9.8 from the command line gives an error "FODC0002: I/O error reported by XML parser processing ... unknown protocol: data".
So my first question is: is that support for data URIs something added on top of Saxon in oXygen or is that a particular Saxon configuration?
For which functions or in which contexts should the use of data URIs work?
I also get it to work for further simple but kind of meaningless stuff like
but I then hoped to use it with the mentioned load-xquery-module function by providing such a data URI as the location hint of the XQuery module to load:
but when I execute that with an XQuery Saxon 9.8 EE transformation scenario I get an error "XQuery module validation/execution is not supported. Please validate/execute the main XQuery file.".
Should the above work? Why does it fail, and why with that error?
Interestingly enough, when I try to reduce the sample to something that does not use data URIs but the same inline code with
then oXygen gives me the same error "XQuery module validation/execution is not supported. Please validate/execute the main XQuery file." although I can run that code fine with Saxon 9.8 EE from the command line outside of oXygen.
So I am not sure whether the error I get with the previous attempt of "load-xquery-module" is due to problems with the use of a "data" URI in the location-hints or due to the way oXygen calls/uses Saxon. I hope you can clarify that.
As a last test I tried to avoid inlining the XQuery code but still using a data URI with
interestingly enough this then gives a different error: "String index out of range: -21" (oXygen XQuery Saxon 9.8.0.12 EE scenario).
As I can't run such code directly with Saxon as there I get a "java.net.MalformedURLException: unknown protocol: data" I would like to know whether that error is within Saxon or oXygen using Saxon.
For completeness, the sample test2018081903.xq simply has
To my surprise the following works with an XQuery Saxon 9.8.0.12 (tried EE and HE) transformation scenario in oXygen 20.1:
Code: Select all
doc('data:application/xml,' || encode-for-uri('<root><foo>bar</foo></root>'))//foo
Code: Select all
<foo>bar</foo>
That is a surprise as running Saxon 9.8 from the command line gives an error "FODC0002: I/O error reported by XML parser processing ... unknown protocol: data".
So my first question is: is that support for data URIs something added on top of Saxon in oXygen or is that a particular Saxon configuration?
For which functions or in which contexts should the use of data URIs work?
I also get it to work for further simple but kind of meaningless stuff like
Code: Select all
unparsed-text('data:text/plain,' || encode-for-uri('This is a test.'))
Code: Select all
let $query as xs:string := 'xquery version "3.1"; module namespace foo = "http://example.com/foo"; declare function foo:f1() as xs:string { "test" };',
$module as map(*) := load-xquery-module('http://example.com/foo', map { 'location-hints' : 'data:application/xquery,' || encode-for-uri($query) })
return $module?functions(QName('http://example.com/foo', 'f1'))(0)()
Should the above work? Why does it fail, and why with that error?
Interestingly enough, when I try to reduce the sample to something that does not use data URIs but the same inline code with
Code: Select all
let $query as xs:string := 'xquery version "3.1"; module namespace foo = "http://example.com/foo"; declare function foo:f1() as xs:string { "test" };',
$module as map(*) := map { 'functions' : map { QName('http://example.com/foo', 'f1') : map { 0 : function() { 'test' }}}}
return $module?functions(QName('http://example.com/foo', 'f1'))(0)()
So I am not sure whether the error I get with the previous attempt of "load-xquery-module" is due to problems with the use of a "data" URI in the location-hints or due to the way oXygen calls/uses Saxon. I hope you can clarify that.
As a last test I tried to avoid inlining the XQuery code but still using a data URI with
Code: Select all
let $query as xs:string := unparsed-text('test2018081903.xq'),
$module as map(*) := load-xquery-module('http://example.com/foo', map { 'location-hints' : 'data:text/plain,' || encode-for-uri($query) })
return $module?functions(QName('http://example.com/foo', 'f1'))(0)()
As I can't run such code directly with Saxon as there I get a "java.net.MalformedURLException: unknown protocol: data" I would like to know whether that error is within Saxon or oXygen using Saxon.
For completeness, the sample test2018081903.xq simply has
Code: Select all
xquery version "3.1"; module namespace foo = "http://example.com/foo"; declare function foo:f1() as xs:string { "test" };