2

如何创建一个notes元素作为根节点的“单个”结果,以及元素的多个子节点note

这是 中的查询eXide

xquery version "3.0";
    
for $note in collection('/db/tmp')/note
return <notes>{$note}</notes>

输出是:

nicholas@mordor:~/flwor$ 
nicholas@mordor:~/flwor$ lynx http://localhost:8080/exist/rest/db/scripts/notes.xq --dump
<notes>
    <note>
bar
</note>
</notes>
<notes>
    <note>
foo
</note>
</notes>nicholas@mordor:~/flwor$ 
nicholas@mordor:~/flwor$ 

我怎样才能得到一个文档,它有一个notesFirefox 不会阻塞的根元素?

有两个文件,foo.xml并且bar.xml在集合中。

4

1 回答 1

2

XML 必须只有一个根元素。同样在不知道数据结构的情况下,我会假设您想要获取所有数据,notes无论它们嵌套多深。实现这一用途collection($col)//note

xquery version "3.1";
    
<notes>
{
  for $note in collection('/db/tmp')/note
  return $note
}
</notes>

或者

xquery version "3.1";
    
<documents>
{
  for $doc in collection('/db/tmp')/document()
  return <notes>{$doc/note}</notes>
}
</documents>

于 2020-11-22T12:15:15.160 回答