簡體   English   中英

如何在一行 output 中為 MarkLogic 中的 XQuery 獲取 output?

[英]How do I get output for a XQuery in MarkLogic in a one line output?

將詳細說明 - 當我執行以下命令時:

let $value := xdmp:forest-status(
                xdmp:forest-open-replica(
                  xdmp:database-forests(xdmp:database("Documents"))))
return $value

上面的查詢返回了很多關於數據庫“文檔”林的信息,比如 - forest-id、host-id 等。

我只要求它應該只返回我的森林的“狀態”。 我怎么做?

使用 XPath 到 select 你想返回什么。

let $value := xdmp:forest-status(
                xdmp:forest-open-replica(
                  xdmp:database-forests(xdmp:database("Documents"))))
return $value/*:state/text()

此外,無需 FLWOR,您可以將其設為單線:

xdmp:forest-status(
  xdmp:forest-open-replica(
    xdmp:database-forests(xdmp:database("Documents"))))/*:state/text()

或者您可能會發現使用箭頭運算符使事情更容易閱讀,而不是嵌套的 function 調用和大量括號包裹它們:

(xdmp:database("Documents")
  => xdmp:database-forests()
  => xdmp:forest-open-replica()
  => xdmp:forest-status()
)/*:state/text()

響應中的 XML 元素位於http://marklogic.com/xdmp/status/forest命名空間中。 因此,您要么需要聲明命名空間(即declare namespace f = "http://marklogic.com/xdmp/status/forest"; )並使用 XPath 中的前綴(即f:state ),要么只使用我所做的通配符*:state

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM