[英]Search only those XMLs when a particular element occurs multiple times in Marklogic
我试图在Marklogic中多次搜索包含元素<document>
文档XML。 以下是我要检索的一个这样的文档XML的结构:
<root>
<documents>
<document>
<id>1</id>
<name>roy</name>
<otherData></otherData>
</document>
<document>
<id>2</id>
<name>roy</name>
<otherData></otherData>
</document>
....
...
..
.
<document>
<id>3</id>
<name>roy</name>
<otherData></otherData>
</document>
</documents>
</root>
我不想检索具有以下结构的XML:
<root>
<documents>
<document>
<id>3</id>
<name>roy</name>
<otherData></otherData>
</document>
</documents>
</root>
我可以使用带有xs:QName("document")
element-query
搜索是否存在或最少一个,但是不确定如何进行多个搜索。
任何帮助将非常感激。
在MarkLogic中,没有真正简单的方法可以很好地进行扩展。 最简单的方法是充实文档,在<documents>
元素中添加count属性,并在每次触摸文档时保持其最新状态。 然后,您可以对count属性进行简单的范围索引,并直接获得所需的内容。
HTH!
我喜欢接受的答案,但尝试同时使用cts:search和XPATH做不同的事情。 它比仅使用XPATH更快:
xquery version "1.0-ml";
let $query1:= cts:element-query(xs:QName("document"),cts:and-query( () )),
$query2:= cts:element-query(xs:QName("documents"),$query1)
return
for $doc in cts:search(collection(),$query2,("unfiltered")) where count($doc/root/documents/document) > 1 return $doc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.