Hi,
whenever I define the type of a parameter as xs:anyURI and pass a string to it, I get the error "Cannot convert xs:string to xs:anyURI". I am aware, that xs:anyURI gets automatically cast to xs:string, whenever needed. But why not the other way around? Especially, since in the hierarchy of types, xs:string is ancestor to xs:anyURI.
I should have added, that this also does not succeed:
declare variable $local:uri1 as xs:anyURI := xs:anyURI(" http://example.com/batz/mongo/blah/index.html");
which leaves me even more baffled.
whenever I define the type of a parameter as xs:anyURI and pass a string
to it, I get the error "Cannot convert xs:string to xs:anyURI".
It might comfort you to hear that the behavior is indeed compliant with the spec. As it would take some time to recite the reasons for this, feel free to scan the following sections:
https://www.w3.org/TR/xquery-31/#id-function-conversion-rules https://www.w3.org/TR/xquery-31/#promotion
I should have added, that this also does not succeed:
...
which leaves me even more baffled.
Me too, because the following query works on my environment:
declare variable $local:uri1 as xs:anyURI := xs:anyURI("http://example.com/batz/mongo/blah/index.html"); $local:uri1
On Mon, Aug 13, 2018 at 7:25 PM Christian Grün christian.gruen@gmail.com wrote:
https://www.w3.org/TR/xquery-31/#id-function-conversion-rules https://www.w3.org/TR/xquery-31/#promotion
Thanks for the links. Will check.
Me too, because the following query works on my environment:
declare variable $local:uri1 as xs:anyURI := xs:anyURI("http://example.com/batz/mongo/blah/index.html"); $local:uri1
Indeed, now it does, for me too. I also found the error I made. Thanks.
So, I just came around this:
declare variable $local:uri as xs:anyURI := xs:anyURI(" HTtpS://reGexr.com/more/less/path/foo.php?q=bar&same[12]=xxx&same[11]=#sldns13123nfdwdw "); $local:uri
The error I get is
[XPST0003] Invalid entity: '&same[12]=xxx&same[1...'.
so I encoded the '&' to '&'.
declare variable $local:uri as xs:anyURI := xs:anyURI(" HTtpS://reGexr.com/more/less/path/foo.php?q=bar&same[12]=xxx&same[11]=#sldns13123nfdwdw "); $local:uri
which results in:
Error: Stopped at C:/Users/user/Desktop/file3, 1/55: [FORG0001] Cannot convert xs:string to xs:anyURI: " HTtpS://reGexr.com/more/less/path/foo.p....
The only way I found to circumvent this, was to encode it via the entity reference and then use encode-for-uri(), but that function/topic seems to be a beast for itself...
On Mon, Aug 13, 2018 at 7:25 PM Christian Grün christian.gruen@gmail.com wrote:
whenever I define the type of a parameter as xs:anyURI and pass a
string to it, I get the error "Cannot convert xs:string to xs:anyURI".
It might comfort you to hear that the behavior is indeed compliant with the spec. As it would take some time to recite the reasons for this, feel free to scan the following sections:
https://www.w3.org/TR/xquery-31/#id-function-conversion-rules https://www.w3.org/TR/xquery-31/#promotion
I should have added, that this also does not succeed:
...
which leaves me even more baffled.
Me too, because the following query works on my environment:
declare variable $local:uri1 as xs:anyURI := xs:anyURI("http://example.com/batz/mongo/blah/index.html"); $local:uri1
[FORG0001] Cannot convert xs:string to xs:anyURI: " HTtpS://reGexr.com/more/less/path/foo.p....
Your URI string contains invalid characters. The first query yields a result, the second doesn’t:
xs:anyURI("[") xs:anyURI("%5b")
There are various ways to get this cleaned up. For example, you can use fn:encode-for-uri [1]. Or have a look at the web:create-url convenience function of BaseX:
web:create-url( 'HTtpS://reGexr.com/more/less/path/foo.php', map { 'q': 'bar', 'same[12]': 'xxx' } )
[1] https://www.w3.org/TR/xpath-functions-31/#func-encode-for-uri [2] http://docs.basex.org/wiki/Web_Module#web:create-url
The only way I found to circumvent this, was to encode it via the entity reference and then use encode-for-uri(), but that function/topic seems to be a beast for itself...
On Mon, Aug 13, 2018 at 7:25 PM Christian Grün christian.gruen@gmail.com wrote:
whenever I define the type of a parameter as xs:anyURI and pass a
string to it, I get the error "Cannot convert xs:string to xs:anyURI".
It might comfort you to hear that the behavior is indeed compliant with the spec. As it would take some time to recite the reasons for this, feel free to scan the following sections:
https://www.w3.org/TR/xquery-31/#id-function-conversion-rules https://www.w3.org/TR/xquery-31/#promotion
I should have added, that this also does not succeed:
...
which leaves me even more baffled.
Me too, because the following query works on my environment:
declare variable $local:uri1 as xs:anyURI := xs:anyURI("http://example.com/batz/mongo/blah/index.html"); $local:uri1
-- Minden jót, all the best, Alles Gute, Andreas Mixich
Is it not the case that because xs:anyURI is derived from xs:string, you can always go "up" the derivation, because the derived type is less general and always remains an instance of the more general type, but the more general type (casting "down" the path of derivation) is not necessarily an instance of the more derived type?
"``````````" is an entirely legitimate string, but it's not a URI, for example.
So I think you might have to use (in your second example) one of the "make a URI" functions like iri-to-uri() or encode-for-uri() which make sure the string fits in the URI type.
-- Graydon
On Mon, Aug 13, 2018 at 12:35 PM Andreas Mixich mixich.andreas@gmail.com wrote:
I should have added, that this also does not succeed:
declare variable $local:uri1 as xs:anyURI := xs:anyURI("
http://example.com/batz/mongo/blah/index.html");
which leaves me even more baffled.
-- Minden jót, all the best, Alles Gute, Andreas Mixich
basex-talk@mailman.uni-konstanz.de