Updating Data Sources


DataDirect XQuery provides a feature that allows XQuery to automatically update data sources that are accessed through doc() and collection() functions. You can use both literal and computed arguments for these function calls.

Relational data sources cannot be updated using automatic update.

Enabling Automatic Update

The automatic update feature can be enabled in one of two ways:

The automatic update feature is disabled by default. When it is enabled, data sources affected by XUF update expressions are physically modified at the end of the XQuery execution.

In the event of a conflict between command line and XQuery settings for this feature, the setting specified at the XQuery level always takes precedence.

How Updates are Performed

Single data sources specified in a doc() function call are updated at the end of the XQuery execution. For a collection() function call that returns n XML documents, each of those n XML documents whose XDM instance has been modified is automatically updated.

Modified files are serialized using global serialization options set through the XQJ API or the ddtek:serialize option. See Serialization Support for more information.

Example

In the following example, the <subject> element in books.xml is renamed to <topic>. Changes to books.xml are saved automatically when the XQuery execution is complete:

declare option ddtek:automatic-update "yes"; 
 
for $book in doc("file:///c:/myFiles/my_books.xml")/books/book 
return  
  rename node $book/subject as QName("","topic")