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

Wolfgang wolfgang at exist-db.org
Tue Sep 2 14:18:22 PDT 2008

> 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.


More information about the talk mailing list