2

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 Answers1

1

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

adamretter
  • 3,885
  • 2
  • 23
  • 43
  • "Your first statement is really saying insert some child node into every document-node in the collection." - This does clarify why my logic does not work. Still trying to find a solution though. Thanks for the response. – user3927794 Aug 10 '14 at 23:34
  • It seems like copying the entire document, adding new elements to the root and removing the old, would be the only way to accomplish this in DBXML without writing additional python logic. – user3927794 Aug 10 '14 at 23:36