在 prolog 中声明的 URI 字符串变量返回错误"not a sub-type of xs:anyURI"



在Xquery 3.1(eXist 4.7(中,我正在使用httpclient函数发送GET请求:

httpclient:get($url as xs:anyURI, $persist as xs:boolean, $request-headers as 
element()?) as item()

我的函数如下所示:

declare function example:get()
{
let $url := "https://api.example.org/groups/1234/items?format=atom&content=tei&v=3"              
let $APIdoc := httpclient:get($url,true(),<headers/>)
return $APIdoc
};

它执行得很好。

但是如果我像这样在prolog中声明相同的URI字符串:

declare variable $example:API_URL := "https://api.example.org/groups/1234/items?format=atom&amp;content=tei&amp;v=3";
declare function example:get()
{
let $APIdoc := httpclient:get($example:API_URL,true(),<headers/>)
return $APIdoc
};

我收到以下错误:

err:XPTY0004 xs:string(https://api.example.org/groups/1234/itemsformat=atom&content=tei&v=3( 不是 xs:anyURI 的子类型

为什么在函数和 prolog 中声明的 URI 字符串之间存在差异?

如何解决此问题,以便我可以使用在prolog中声明的URI字符串变量?

我认为根据W3C 规范,这些都不应该成功:您可以在需要字符串的地方使用 URI,但不能反过来。解决方案很简单:通过写入将字符串转换为 URI

httpclient:get(xs:anyURI($example:API_URL), ...)

相关内容

最新更新