xml - 如何使用 eXist-db 将 "stitch together"结果转换为单个 XML 文档?

标签 xml syntax exist-db flwor restxq

如何创建一个 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.xmlbar.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/

相关文章:

c++ - Boost::ptree 解析器无法从 xml 文件中读取容器

java - Java .properties 文件中与键值模式不匹配的行会发生什么情况

java - 在 EditText 上设置 columnWeight

嵌套循环中++ 的 Ruby 优雅替代方案?

java - eXist-db 从同一集合的许多 XML 中获取数据

android - 嵌套 ScrollView + TextView + RecyclerView

c# - c#中的 `new object()`和 `new {}`有区别吗?

javascript - 为 JavaScript 函数参数转义 PHP 中的引号

参数的存在数据库基数

xml - 用于声明命名空间的 XQuery 语法 : [XPST0081] No namespace declared for 'text:p'