Update multiple XML files using XQuery

Issues related to W3C XQuery.
fhorn
Posts: 18
Joined: Mon Dec 09, 2013 7:47 pm

Update multiple XML files using XQuery

Post by fhorn » Thu Apr 16, 2015 10:34 pm

Hello,

I've got problems to update several documents using a XQuery Update.
The oxygen version is 16. I use Saxon-EE XQuery 9.5.1.5. as a transformer and disabled XQuery 3.0 support.

Here is an example:

Code: Select all

xquery version "1.0";
let $docs := collection("file:///C:/My_Collection/?select=*.xml")
for $doc in $docs
return
replace value of node $doc/rootElement/element with 'new value'
I receive the following error message:
Updated document discarded because it was not read using doc(). Warning

If I try

Code: Select all

replace value of node doc($doc)/rootElement/element with 'new value'
I receive the following message: java.io.FileNotFoundException

It works if I modify the script and update only one file

Code: Select all

let $doc := doc("file:///C:/My_Collection/File.xml")
return
replace value of node $doc/rootElement/element with 'new value'
It would be great if you could give some advice how to modify the xquery script
to update multiple files?

Thanks,
Franziska

Radu
Posts: 6561
Joined: Fri Jul 09, 2004 5:18 pm

Re: Update multiple XML files using XQuery

Post by Radu » Wed Apr 22, 2015 1:08 am

Hi Franziska,

Oxygen uses the Saxon processor to run XQuery updated. So ideally you could register and write about this on the Saxon Help Users List:

http://sourceforge.net/p/saxon/mailman/

Looking for this a little bit on the web, it seems that indeed for each document that you want to modify you would need to use the doc function to load it.
Maybe as a possibly silly workaround after you use the collection function, for each of the documents you can use the document-uri function to find out the system ID and load it again using the doc function, then perform the update on it.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

fhorn
Posts: 18
Joined: Mon Dec 09, 2013 7:47 pm

Re: Update multiple XML files using XQuery

Post by fhorn » Wed Apr 22, 2015 11:17 am

Hello,

thank you very much for your response! It works if I use the document-uri function as you suggested it.

Code: Select all

replace value of node doc(document-uri($doc))/rootElement/element with 'new value'
Regards,
Franziska

Post Reply