首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >marklogic xdmp:http-post选项参数问题

marklogic xdmp:http-post选项参数问题
EN

Stack Overflow用户
提问于 2020-02-20 05:52:17
回答 2查看 80关注 0票数 1

尝试从另一个config构建选项参数,以传递xdmp:http-post函数。

代码语言:javascript
复制
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

上述代码的输出如下:

代码语言:javascript
复制
<options xmlns="xdmp:http">
  <authentication method="digest">
    <username>
    </username>
    <password>
    </password>
 </authentication>
</options>

无法理解为什么xpath返回为空。移除xmlns="xdmp:http"命名空间时,获得正确的输出。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-02-20 08:57:24

对,是这样。在XQuery内部的默认命名空间中使用文字元素是一个非常微妙的副作用。最简单的方法是使用*:前缀通配符:

代码语言:javascript
复制
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

还可以预先计算文字元素之前的值:

代码语言:javascript
复制
let $db-config :=
  <config>
      <user-name>admin</user-name>
      <password>admin</password>
  </config>
let $user as xs:string := $db-config/user-name
let $pass as xs:string := $db-config/password
let $options :=
        <options xmlns="xdmp:http">
            <authentication method="digest">
                <username>{$user}</username>
                <password>{$pass}</password>
            </authentication>
        </options>
return $options

或者使用元素结构:

代码语言:javascript
复制
let $db-config :=
  <config>
      <user-name>admin</user-name>
      <password>admin</password>
  </config>
let $options :=
        element {fn:QName("xdmp:http", "options")} {
            element {fn:QName("xdmp:http", "authentication")} {
                attribute method { "digest" },

                element {fn:QName("xdmp:http", "username")} {
                    $db-config/user-name/text()
                },
                element {fn:QName("xdmp:http", "password")} {
                    $db-config/password/text()
                }
            }
        }
return $options

哈哈!

票数 1
EN

Stack Overflow用户

发布于 2020-02-20 08:54:14

这是因为您试图从没有命名空间的xml中获取值,并将其放入带有命名空间的xml中。你可以把你的代码修改成-

代码语言:javascript
复制
xquery version "1.0-ml";
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

有关名称空间工作方式如何通过https://docs.marklogic.com/guide/xquery/namespaces#chapter的更多了解

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60313675

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档