Learn About XQuery Update Facility


XQuery Update Facility is an extension of the XQuery language that allows you to make changes in an XML document using “update expressions” that insert, delete, replace, or rename nodes. This extension provides a convenient way to make intelligent updates to XML documents, and XMLSpy has a unique implementation that makes it even easier. Let’s see how it works.

News about XML find / replace

What is XQuery Update Facility?

XQuery Update Facility (XQUF) is an XQuery language extension specifying FLWOR expressions that can be used to make persistent changes to XML instance(s). These expressions update nodes using any or all of the following operations:

  • Insert a node
  • Delete a node
  • Replace a node and its descendants
  • Replace the contents or value of a node
  • Rename a node

For instance, in the screenshot below, we’re using XQuery Update to replace the value of a node by adding a “1” to the phone extension for employees in US-based offices and a “2” to other extensions to accommodate a change to a four-digit phone extension.

XQuery Update in XMLSpy

XMLSpy supports both XQuery Update 1.0 and 3.0.

The XQuery Update Facility editor shown below makes it easy to compose and test the five types of update expressions with syntax coloring, code completion, and error message reporting. You can preview the results of your update expressions as you type for easy troubleshooting, and clicking on a result tin the preview window highlights the affected node in your instance document. Then, you can execute the updates with one click — either in the current file or across all open files, a folder, or an entire XMLSpy project.

XQuery Update Facility

XQuery Update statements are also supported during full execution of an XQuery document (Alt + F10).

What makes the XMLSpy implementation so innovative?

According to the standard, that the result of an XQuery Update execution is a new XML file based on the original file and the specified modifications. This means that each execution completely reformats the document.

XMLSpy lets you skip this intermediary step, because it allows you to make updates directly in the specified XML file(s) without having to create a new file.

In this way, you’re armed with an intelligent mechanism for implementing XQuery Update via a familiar find-and-replace paradigm. However, because XQuery Update provides for sophisticated updates using the power of FLWOR statements, it overcomes the limitations of find-and-replace and lets you make complex, intelligent XML file modifications quickly and easily.

How does it work?

See how it all works in this brief video, which walks you quickly through editing XQuery Update expressions in XMLSpy and also serves as a quick tutorial about how XQuery Update Facility works if you’re unfamiliar with the syntax.

To try working with XQuery Update Facility yourself, you can download a free trial of XMLSpy.

Tags: , , ,