尝试从另一个配置XML构建选项参数以传递xdmp:http-post
函数。
let $db-config :=
<config>
<user-name>admin</user-name>
<password>admin</password>
</config>
let $options :=
<options xmlns="xdmp:http">
<authentication method="digest">
<username>{$db-config/user-name/text()}</username>
<password>{$db-config/password/text()}</password>
</authentication>
</options>
return $options
以上代码的输出是:
<options xmlns="xdmp:http">
<authentication method="digest">
<username>
</username>
<password>
</password>
</authentication>
</options>
无法理解为什么xpath返回空白。在删除xmlns="xdmp:http"
名称空间时,将获得正确的输出。
这是因为您试图从不带名称空间的xml中获取值,并将其放入具有名称空间的xml中。您可以将代码修改为此-
正确。在XQuery内部的默认名称空间中使用文字元素是非常微妙的副作用。最简单的方法是使用*:前缀通配符: