Database Reference
In-Depth Information
update insert <LogEntry> Something happened... </LogEntry> into
doc ( '/db/logs/mainlog.xml' )/ *
The following (somewhat more complicated) example makes sure that the number of
messages does not exceed 10, and that the most recent message is on top:
let $ document := doc ( '/db/logs/mainlog.xml' )
let $ newentry := <LogEntry> Something happened... </LogEntry>
return
update delete $ document / * / LogEntry [ position () ge 10 ],
if ( exists ( $ document / * / LogEntry [ 1 ]))
then update insert $ newentry preceding $ document / * / LogEntry [ 1 ]
else update insert $ newentry into $ document / *
All eXist XQuery update statements start with the keyword update , followed by an
update action. Available actions are delete , insert , rename , replace , and value .
The return type of an update statement is always the empty sequence () .
An eXist update statement can only be used to update persistent XML documents
stored in the database. It cannot be used to update temporary documents or docu‐
ment fragments stored in memory. For example, the following code fragment is ille‐
gal and will result in an error:
(: This is invalid: :)
let $ document as document-node () := <Root><a/></Root>
return
update insert <b/> into $ document / *
You can use eXist's update statements anywhere in your XQuery main code or func‐
tion bodies. However, take care when using them inside a FLWOR expression return
statement. Update statements take effect immediately, and changing the structure
your query is looping over may lead to some unexpected results!
update delete
update delete simply deletes nodes. Its syntax is:
update delete expr1
where expr1 is an XQuery expression resolving to any kind of node. All nodes in
expr1 will be deleted by this statement.
Note that you cannot delete document root elements with update delete .
update insert
update insert inserts content into an element node. Its syntax is:
update insert expr1 [ into | following | preceding ] expr2
Search WWH ::




Custom Search