Skip to main content
 首页 » 编程设计

python之DBXML XQuery : move child to root of container

2025年05月04日11oomusou

我正在使用 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) 
) 

请您参考如下方法:

我希望您不能使用 XQuery 更新集合。

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

您的第一条语句实际上是在说将一些 child 节点插入到集合中的每个文档节点中。

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