DBXML XQuery:将子移动到容器的根目录

时间:2014-08-10 21:24:27

标签: python xml xquery xquery-update berkeley-db-xml

我正在使用python中的xquery更新并尝试从xml树中提取子元素并将它们作为新的父元素插入到DBXML数据库中。使用以下xquery,我试图迭代每个子节点,然后将子节点插回到父集合中。

for $child in collection($items)/parent/path/to/child return (
    insert node $child into collection($items)
)

但是,会产生以下错误。

XmlQueryEvaluationError Error: Cannot perform an update that creates a persistent document with more than one document element, line 0, column

我也尝试插入带有变量值的xml,但是定义了所有节点。产生了同样的错误。

for $child in collection($items)/parent/path/to/child return (
    insert node <parent><item>{$child/item}</item></parent> into collection($items)
)

1 个答案:

答案 0 :(得分:1)

我希望你不能XQuery更新集合。

而不是fn:collection作为更新语句的上下文,您很可能必须提供单个文档节点或其他节点。

您的第一个声明实际上是说将一些child节点插入集合中的每个文档节点。

如果您只想使用XQuery插入新文档,我不确定这在DBXML中是否可行:http://docs.oracle.com/cd/E17276_01/html/intro_xml/modifyingdocuments.html