Christian,
As always, thank you for your help! I had tried the following
```xquery
declare function local:grab2(
$url as xs:string,
$path as xs:string,
$fname as xs:string
) as document-node() {
let $req := http:send-request(<http:request method="get"/>, $url)
return
if (head($req)/@status = "200")
then file:write($path || $fname, tail($req), map { "method": "xml" })
else document { element error { "something went wrong" } }
};
```
and had the same error - adding an occurrence indicator on the return type solves it for that trial, too.
Much appreciated!
Best,
Bridger