Page 1 of 1

Update multiple XML files using XQuery

Posted: Thu Apr 16, 2015 10:34 pm
by fhorn
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

Re: Update multiple XML files using XQuery

Posted: Wed Apr 22, 2015 1:08 am
by Radu
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

Re: Update multiple XML files using XQuery

Posted: Wed Apr 22, 2015 11:17 am
by fhorn
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