DBXML XQuery: move child to root of container

231 Views Asked by At

I am working with xquery updates in python and attempting to pull child elements out of the xml tree and insert them as new parent elements in the DBXML database. With the following xquery I was attempting to iterate each child and then insert the child back into the parent collection.

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

However, the following error is produced.

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

I have also tried inserting xml with variable values but all nodes defined. Same error is produced.

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

There are 1 best solutions below

2
On

I would expect it to be the case that you cannot XQuery Update a Collection.

Instead of fn:collection as the context for your update statement, you most likely have to provide a single document-node or other node.

Your first statement is really saying insert some child node into every document-node in the collection.

If you want to insert a new document using just XQuery, I am not sure this is possible in DBXML: http://docs.oracle.com/cd/E17276_01/html/intro_xml/modifyingdocuments.html