Xquery prolog中声明的URI字符串变量返回错误“不是xs:anyURI的子类型”

Xquery prolog中声明的URI字符串变量返回错误“不是xs:anyURI的子类型”,xquery,exist-db,Xquery,Exist Db,在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?fo

在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
};
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
};
它执行得很好

但如果我在序言中声明相同的URI字符串,如下所示:

declare function example:get()
{
   let $url := "https://api.example.org/groups/1234/items?format=atom&amp;content=tei&amp;v=3"              
   let $APIdoc := httpclient:get($url,true(),<headers/>)
   return $APIdoc
};
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
};
我收到以下错误:

错误:XPTY0004 xs:string不是xs:anyURI的子类型

为什么函数和prolog中声明的URI字符串会有区别


如何解决这个问题,以便使用序言中声明的URI字符串变量?

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

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

它的构建方式可能不会自动强制为所需的类型。尝试通过将URL变量包装成xs:anyURI来显式强制转换它。xs:anyURI有效,谢谢。我的第一个函数确实在existdb中工作。事实上,如果我首先将prolog字符串传递给另一个局部变量,那么我也可以使用它。