Sedna LogoBackground Top
 
Home  |  Getting Started  |  Documentation  |  Demo  |  Download  |  Support 

2.3 Update Language

The update language is based on the XQuery update proposal by Patrick Lehti [6] with the number of improvements.

Note 2 The result of each update statement, shouldn’t break the well-formedness and validness of XML entitites, stored in the database. Otherwise, an error is raised.

INSERT

The insert statement inserts content at positions identified by the into, preceding and following clauses.

UPDATE  
insert Expr1 (into|preceding|following) Expr2

Expr1 identifies the ordered sequence of the nodes to be inserted. The into, preceding or following clause identifies the position. For each node in the result sequence of Expr2, the result sequence of Expr1 is inserted to the position identified by the into, preceding or following clauses. If the into clause is specified, the sequence is appended to the random position of the child sequence for each node in the result of Expr2. If the preceding clause is specified, the sequence is appended before each node in the result of Expr2. If the following clause is specified, the sequence is appended after each node in the result of Expr2.

If one of the following conditions is met an error occurs:

  • There are non-element nodes in the result of Expr2 in case of the into clause
  • There are temporary nodes in Expr2 (a node is considered temporary, if it is created as the result of the XQuery constructor evaluation.)
UPDATE  
insert <warning>High Blood Pressure!</warning>  
preceeding doc("hospital")//blood_pressure[systolic>180]

DELETE

The DELETE statement serves to remove persistent nodes from the database. It contains a subexpression, that returns the nodes to be deleted.

UPDATE  
delete Expr

Expr identifies the nodes to be removed from the datatbase. Note, that nodes are removed from the database with all their descandants.

If one of the following conditions is met an error occurs:

  • There are nodes in the result sequence of Expr that are not stored in external memory
UPDATE  
delete doc("hospital")//blood_pressure[systolic>180]

DELETE_UNDEEP

UPDATE  
delete_undeep Expr

The DELETE_undeep statement removes nodes identified by Expr, but in contrast to the DELETE statement it leaves the descendants of the nodes in the database.

Consider the following example:

A document named "a.xml" before update:  
<A>  
<B>  
<C/>  
<D/>  
</B>  
</A>  
 
UPDATE  
delete_undeep doc("a.xml")//B  
 
The document after update:  
<A>  
<C/>  
<D/>  
</A>

REPLACE

The REPLACE statement is used to replace nodes in an XML document in the following manner. Each node returned by Expr1 is replaced with the sequence of the nodes returned by Expr2 where $var is bound to the node. Note that Expr2 is executed over the original document without taking into account intermediate updates performed during execution of this statement.

If one of the following conditions is met, an error occurs:

  • There are atomic values in the result of Expr1
  • There are temporary nodes in Expr1 (a node is considered temporary, if it is created as the result of the XQuery constructor evaluation.)

The $var variable bound in replace clause may have an optional type declaration. If the type of a value bound to the variable does not match the declared type, an error is raised.

UPDATE  
replace $var [as type] in Expr1  
with Expr2($var)

In the following example the salary of persons named ”John” is doubled.

UPDATE  
replace $p in doc("foo.xml")/db/person[name="John"]  
with  
<person>  
{($p/@*,  
  $p/node()[not(self::salary)],  
  for $s in $p/salary  
  return <salary>{$s*2}</salary>)}  
</person>

RENAME

The RENAME statement is used to change the qualified name of an element or attribute.

UPDATE  
rename Expr on QName

The following expression changes the name of <job/> elements without changing their contents:

UPDATE  
rename doc("foo.xml")//job[.="bit banger"] on profession