Updating Data Sources
DataDirect XQuery provides a feature that allows XQuery to automatically update data sources that are accessed through
doc()
andcollection()
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:
- Using the
ddtek:automatic-update
option. The automatic update feature can be enabled in any XQuery using the following declaration:
declare option ddtek:automatic-update "yes"
- Using the
-u
command line option. See Using the Command Line Utility for more information on using the command line.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 acollection()
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: