Updating xml file using xquery

You want a single XQuery that will be used to save new data and update existing data.If a form is used to update an existing record, you can assume that it has an tag in the XML document being saved.

updating xml file using xquery-39updating xml file using xquery-21

I am not quite sure to understand what difficulty you found.

What you try to achieve is certainly possible with XQuery (or with XSLT, which is more convenient for transforming XML trees, especially for multiple transform passes).

IMHO it is also more aligned with the concept of ACID transactions in databases.

So it might look surprising in some cases, but when you know how it works, it is easy: in your test condition, it can never see the new attributes created in the same query at all.

Only after the entire query has been evaluated, then all the changes are played at once.

The main effect for a developer, is that you cannot see a change made in another part of the query.

Note that if you use update statements on a document stored in a whole document container, then you might lose some of your document's formatting.

This is because update statements reparse the documents they operate upon and then ultimately store them back in the container in the format used for node storage containers.

The changes are applied all at once, that's the processing model for XQuery Update (without entering details here, that is a property that allows to optimize and "parallelize" XQuery code, even with updates, by defining them as non-side-effect updates.) That is "their job": be applied at once, and throw an error for inconsistencies (what else could they do? , silently chose on your behalf what node to ignore, based on no logic?

Is there a simple way using the Zorba XQuery Processor to update multiple XML files and save the output of the modification back in the same file?

The problem is that this doesn't actually modify the file.

Tags: , ,