[xquery-talk] Changing the content of an XML document

Piewald, Georg georg.piewald at siemens.com
Tue Sep 2 14:51:18 PDT 2008


 

> Wolfgang [mailto:wolfgang at exist-db.org] wrote:
> 
>> I tried the following, which is obviously wrong:
>> 
>> declare function local:alter() {
>> let $myfile := doc('/db/myfile.xml')
>> return update value $myfile/subnode/text() with
>> 	'some other text'
>> };
> 
> No, that's basically ok. Just make sure that $myfile/subnode/text() 
> returns something. I guess you may need 
> $myfile//subnode/text() instead.
> 
> Note: eXist's update syntax is still based on some old proposals (the 
> implementation nevertheless works very well). The first XQuery update 
> drafts were published later and I had no time to adopt this stuff yet 
> (it doesn't have the highest priority for me personally).
> 
> > I'm neither sure how to specify the document I want to 
> alter (the doc()
> > function is surely wrong since it loads the file into 
> memory) nor how to
> > select the textnode using XPath (is /text() required here?).
> 
> doc("/db/myfile.xml") doesn't "load" the document into memory 
> (it is a 
> persistent document whose nodes reside on disk). It just returns a 
> reference to that document.

Great, now it works perfectly fine!

Just one thing that I find a bit strange: the entire "update value ..."
expression doesn't seem to actually return anything (though the file in
the db is altered as expected). So instead I had to introduce a
dummy-variable like this:

let $myfile := doc('/db/myfile.xml')
let $dummy := update value $myfile//subnode/text() with
	'some other text'
return $myfile

Is it supposed to be like that?
However, I'm happy with the current solution, thanks a lot for helping!
Georg



More information about the talk mailing list