在XQuery3.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&content=tei&v=3";
declare function example:get()
{
let $APIdoc := httpclient:get($example:API_URL,true(),<headers/>)
return $APIdoc
};我收到以下错误:
err:xs 0004 xs:string(https://api.example.org/groups/1234/itemsformat=atom&content=tei&v=3)不是xs:anyURI的子类型。
为什么在函数中声明的URI字符串和prolog中声明的URI字符串之间会有区别?
如何解决这个问题,以便使用prolog中声明的URI字符串变量?
发布于 2019-09-14 17:42:40
根据W3C规范,我认为其中任何一个都不应该成功:您可以在需要字符串的地方使用URI,但不能使用相反的方式。解决方案很简单:通过编写
httpclient:get(xs:anyURI($example:API_URL), ...)https://stackoverflow.com/questions/57935082
复制相似问题