Updating xml file using xquery
There’s something slightly oxymoronic about the phrase XQuery Update Facility.Make your mind up, dude – are you querying or updating? But as, with each passing year, XQuery got more powerful and more popular the lack of an ability to modify XML documents began to look more and more like a gaping hole.I’ve never been one of those geeks who cares too deeply about execution plans as long as my queries run reasonably quickly. ” But this quirk does have two major impacts on XQUF. The second consequence of this XQUF quirk is that you cannot, therefore, query XQUF changes in the same command in which you are making them.Firstly, it means that your XQUF operations can be written in pretty much any order you like, which is nice. And that’s because those changes are not executed until the end of that command.The way to change the value of an attribute, is to change its text value.
To forward information from the XQuery to the XUpdate, one had to dynamically construct an XUpdate XML fragment, passing the required XPath expressions as strings.
An update statement may occur at any position within the XQuery main code or a function body.
When using an update within the return clause of a FLWOR expression, it should be clear that one should not delete or replace nodes that are still being used by enclosing code.
But we’re getting a little ahead of ourselves here.
Let me introduce you to the 5 basic XQUF operations.