[英]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.