如何创建一个 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$
如何获取单个文档,其中包含 notes
的单个根元素,而 Firefox 则无法获取 choke开?
集合中有两个文件,foo.xml
和 bar.xml
。
最佳答案
XML 必须只有一个根元素。
另外,在不知道数据结构的情况下,我会假设您想要获取所有注释,无论它们嵌套的深度如何。要实现这一点,请使用 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>
关于xml - 如何使用 eXist-db 将 "stitch together"结果转换为单个 XML 文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64953382/