[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

Changing the content of an XML document

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


  Changing the content of an XML document
 

> Wolfgang [mailto:http://x-query.com/mailman/listinfo/talk] 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



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.