Support for data URIs in XQuery with Saxon in oXygen
Issues related to W3C XQuery.
-
- Posts: 102
- Joined: Tue Aug 19, 2014 12:04 pm
Support for data URIs in XQuery with Saxon in oXygen
Post by Martin Honnen »
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" };
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Support for data URIs in XQuery with Saxon in oXygen
Hi Martin,
Both Oxygen and Saxon are Java application. There are various URL protocols like "file", "http" or in your case "data". Some of them are implemented in the standard Java libraries bundled with the Java Virtual Machine but "data" is not one of them. Oxygen's main Java library adds support for this "data" URL protocol which is used also by Saxon when running from Oxygen. But when Saxon runs from the command line, it uses the standard Java URL protocols and so it no longer has support for "data".
About your other problem:
Because you use the "module namespace" keywords in the XQuery, Oxygen suspects it's an XQuery module and because it does not have support to validate XQuery modules it issues that error message that you posted. Usually if you want to validate XQuery modules in Oxygen you can try to create a custom validation scenario and validate the main XQuery file instead.
Regards,
Radu
Both Oxygen and Saxon are Java application. There are various URL protocols like "file", "http" or in your case "data". Some of them are implemented in the standard Java libraries bundled with the Java Virtual Machine but "data" is not one of them. Oxygen's main Java library adds support for this "data" URL protocol which is used also by Saxon when running from Oxygen. But when Saxon runs from the command line, it uses the standard Java URL protocols and so it no longer has support for "data".
About your other problem:
I looked at the sample xquery file you pasted, honestly I'm not sure what it is. You seem to be using the "module namespace" keywords in it. Is it an XQuery module? But if it's a module, why does it have a return statement? Did you actually want to use the "define namespace" keywords instead?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."
Because you use the "module namespace" keywords in the XQuery, Oxygen suspects it's an XQuery module and because it does not have support to validate XQuery modules it issues that error message that you posted. Usually if you want to validate XQuery modules in Oxygen you can try to create a custom validation scenario and validate the main XQuery file instead.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 102
- Joined: Tue Aug 19, 2014 12:04 pm
Re: Support for data URIs in XQuery with Saxon in oXygen
Post by Martin Honnen »
Thanks for your answer and the explanations so far.
The XQuery code
is a https://www.w3.org/TR/xquery-31/#dt-main-module that happens to contain the code for an XQuery library module as a string. It tries to feed that string, using a URI with the "data" protocol, to the "load-xquery-module" function and then it tries to call a function from that loaded XQuery module.
So does oXygen actually try to run that code when it gives the "XQuery module validation/execution is not supported. Please validate/execute the main XQuery file" and Saxon fails to run it or is that error caused by some non-XQuery evaluation, code sniffing or parsing attempt that in this case then would seem to decide over-eagerly that it has found a module, given that those code keywords are inside a string literal and not part of code?
I hope you can also look into the error caused by
is that Saxon code or oXygen code that gives the "String index out of range: -21"?
The source code of the used test2018081903.xq is at the end of the original question, so I hope I don't have to repeat it.
The XQuery code
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)()
So does oXygen actually try to run that code when it gives the "XQuery module validation/execution is not supported. Please validate/execute the main XQuery file" and Saxon fails to run it or is that error caused by some non-XQuery evaluation, code sniffing or parsing attempt that in this case then would seem to decide over-eagerly that it has found a module, given that those code keywords are inside a string literal and not part of code?
I hope you can also look into the error caused by
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)()
The source code of the used test2018081903.xq is at the end of the original question, so I hope I don't have to repeat it.
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Support for data URIs in XQuery with Saxon in oXygen
Hi Martin,
So:
In this particular case, our "data" URL handler breaks when retrieving content from your "data" protocol. And it's a bug, we'll fix it on our side.
In the meantime you can do something like:
adding that extra charset there should bypass this problem in our code.
Regards,
Radu
So:
As you say, Oxygen tries to sniff around the XQuery content to see if it's a module or not, it finds the keywords "module namespace" and decides that it is a module and no longer validates it. We'll work to improve our module detection, for now if you add an extra space before "module" and "namespace" you should trick our current primitive module detection.So does oXygen actually try to run that code when it gives the "XQuery module validation/execution is not supported. Please validate/execute the main XQuery file" and Saxon fails to run it or is that error caused by some non-XQuery evaluation, code sniffing or parsing attempt that in this case then would seem to decide over-eagerly that it has found a module, given that those code keywords are inside a string literal and not part of code?
As a general rule, whenever after a transformation you have errors in the results view, you can right click them, "Show Message" and then see if the dialog which popup up has a "More details" link. If it does, then this gives additional information about the error stack trace.I hope you can also look into the error caused by
............
is that Saxon code or oXygen code that gives the "String index out of range: -21"?
In this particular case, our "data" URL handler breaks when retrieving content from your "data" protocol. And it's a bug, we'll fix it on our side.
In the meantime you can do something like:
Code: Select all
'location-hints' : 'data:text/plain;charset=utf-8,'
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Support for data URIs in XQuery with Saxon in oXygen
Hi,
Just to update this thread, we released Oxygen 21 which can validate XQuery module and we also fixed that unhandled error with the data URIs.
Regards,
Radu
Just to update this thread, we released Oxygen 21 which can validate XQuery module and we also fixed that unhandled error with the data URIs.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service