简体   繁体   English

如何在一行 output 中为 MarkLogic 中的 XQuery 获取 output?

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

Will elaborate - when I execute the following command:将详细说明 - 当我执行以下命令时:

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

Above query returns a lot of information about the database "Documents" forest, like - forest-id, host-id, etc.上面的查询返回了很多关于数据库“文档”林的信息,比如 - forest-id、host-id 等。

I only require that it should return only the "state" of my forest.我只要求它应该只返回我的森林的“状态”。 How do I do that?我怎么做?

Use XPath to select what you want to return.使用 XPath 到 select 你想返回什么。

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

Also, no need for a FLWOR you could make it a one-liner:此外,无需 FLWOR,您可以将其设为单线:

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

Or you may find that using the arrow operator makes things easier to read instead of nested function calls and tons of parenthesis wrapping them:或者您可能会发现使用箭头运算符使事情更容易阅读,而不是嵌套的 function 调用和大量括号包裹它们:

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

The XML elements in the response are in the http://marklogic.com/xdmp/status/forest namespace.响应中的 XML 元素位于http://marklogic.com/xdmp/status/forest命名空间中。 So, you would either need to declare the namespace (ie declare namespace f = "http://marklogic.com/xdmp/status/forest"; ) and use the prefix in your XPath (ie f:state ), or just use the wildcard as I have done *:state因此,您要么需要声明命名空间(即declare namespace f = "http://marklogic.com/xdmp/status/forest"; )并使用 XPath 中的前缀(即f:state ),要么只使用我所做的通配符*:state

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在MarkLogic XQuery中获取HTTP POST主体? - How do I get the HTTP POST body in MarkLogic XQuery? 使用saxon9he在XQuery中输出文本:如何在输出本身中创建“ &lt;”和“&gt;”,而不进行转义? - outputting text in XQuery using saxon9he: how do I get “<” and “>” created in the output themselves, not escaped? 如何格式化XQuery表达式的XML文件/输出? - How do I format a XML file/output of an XQuery expression? 如何在MarkLogic中以编程方式在XQuery中创建JSON? - How do I programmatically create JSON in XQuery in MarkLogic? 如何在Marklogic XQuery中复制/克隆节点 - How Do I Copy/Clone a Node in Marklogic XQuery 我们如何将 xquery 输出数据保存在另一个没有 Marklogic 的系统的共享位置上 - How can we save xquery output data on shared location of another system that not have Marklogic Marklogic 6如何使用xquery获取属性值? - Marklogic 6 how to get attribute value using xquery? 我能否获得帮助以使用Xquery获得所需的输出? - Can I get help to get the desired output with Xquery? 如何在Marklogic的Xquery中解析“&gt;”和“ &lt;”? - How to parse “>” and “<” in Xquery in Marklogic? 如何获得MarkLogic文档URI到文档中词典(范围索引)值的XQuery映射? - How can I get an XQuery map of MarkLogic document URIs to lexicon (range index) values in the document?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM