XML:DB Home

Index
Requirements
XUpdate WD

Resources

Repository

Mail List
Mail Archive
Authors
Andreas Laux - andreas@smb-tec.com
Lars Martin - lars@smb-tec.com
Status
Working Draft - 2000-09-14
Notice
This is an XML:DB Working Draft for review by all interested parties. It is a draft document and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Working Drafts as reference material or to cite them as other than "work in progress". This work is part of the XML:DB Project.
Abstract
This specification defines the syntax and semantics of XUpdate, which is a language for updating XML documents. XUpdate is designed to be used independently of any kinf of implementation.

Table of Contents


1 Introduction
2 XUpdate Syntax and Document Type Definition
    2.1 Namespace
    2.2 Selections
    2.3 Modifications
    2.4 Inserts
        2.4.1 Creating Elements
        2.4.2 Creating Attributes
        2.4.3 Creating Text
        2.4.4 Creating Processing Instructions
        2.4.5 Creating Comments
    2.5 Append
    2.6 Update
    2.7 Remove
    2.8 Rename
    2.9 Variables and Values of Variables
    2.10 Conditional Processing
    2.11 Document Type Definition for XUpdate
3 Example of Usage

Appendices

A Open Issues
B Normative References
C Other References


Introduction

This specification defines the syntax and semantics of the XUpdate update language. An update in the XUpdate language is expressed as a well-formed [XML] document.

XUpdate makes extensive use of the expression language defined by [XPath] for selecting elements for updating and for conditional processing.

XUpdate is a pure descriptive language which is designed with references to the definition of XSL Transformations [XSLT].


XUpdate Syntax and Document Type Definition

Namespace

The XUpdate namespace has the URI http://www.xmldb.org/xupdate.


Selections

XUpdate uses the expression language defined by [XPath]. Those XPath Expressions are used in XUpdate for selecting nodes for processing afterwards.


Modifications

An update is represented by an xupdate:modifications element in an XML document. An xupdate:modifications element must have a version attribute, indicating the version of XUpdate that the update requires. For this version of XUpdate, the value should be 1.0.

The xupdate:modifications element may contain the following types of elements:

  • xupdate:insert-before
  • xupdate:insert-after
  • xupdate:append
  • xupdate:update
  • xupdate:remove
  • xupdate:rename
  • xupdate:variable
  • xupdate:value-of
  • xupdate:if

Inserts

This section describes XUpdate instructions that directly inserts nodes in the XML result tree. There are two instructions in XUpdate that support insertion of nodes: xupdate:insert-before and xupdate:insert-after. Both elements have a required select attribute, which specifies the node selected by an XPath expression. This select expression must evaluate to a node-set. The appendix of before and after to the definition of insert is meant to specify the direction where - in relation to the selected context node - the new node will be inserted.

xupdate:insert-before inserts the given node as the preceding sibling of the selected context node, where xupdate:insert-after inserts the given node as the following sibling of the selected context node.

The xupdate:insert-before and xupdate:insert-after element may contain the following types of elements:

  • xupdate:element
  • xupdate:attribute
  • xupdate:text
  • xupdate:processing-instruction
  • xupdate:comment

These elements are described below.

Creating Elements

The xupdate:element element allows an element to be created with a computed name.

For example, this


 <xupdate:element name="address"> 
   <town>San Francisco</town> 
 </xupdate:element>

would create the element


 <address> 
   <town>San Francisco</town> 
 </address>

Creating Attributes

The xupdate:attribute element can be used to add attributes to result elements.


 <xupdate:element name="address"> 
   <xupdate:attribute name="id">2</xupdate:attribute> 
 </xupdate:element>

would create the element with an attribute


 <address id="2"/> 

Creating Text

The xupdate:text element can be used to create text nodes in the result tree.


Creating Processing Instructions

The xupdate:processing-instruction element is instantiated to create a processing instruction node. The content of the xupdate:processing-instruction element is a template for the string-value of the processing instruction node. The xupdate:processing-instruction element has a required name attribute that specifies the name of the processing instruction node. The value of the name attribute is interpreted as an attribute value template.

For example, this


 <xupdate:processing-instruction name="cocoon-process"> 
   type="xsp" 
 </xupdate:processing-instruction>  

would create the processing instruction


 <?cocoon-process type="xsp"?>  

Creating Comments

The xupdate:comment element is instantiated to create a comment node in the result tree. The content of the xupdate:comment element is a template for the string-value of the comment node.

For example, this


 <xupdate:comment>
   This element is automatically generated. Do not edit!
 </xupdate:comment>  

would create the comment


 <!--This element is automatically generated. Do not edit!--> 


Append

The xupdate:append element allows a node to be created and appended as a child of the context node. An xupdate:append element must have a select attribute which selects the context node as the parent of the new child node. The select expression must evaluate to a node-set of element nodes. The optional child attribute specifies the position of the newly appended child node. The child expression must evaluate to an Integer value. If this attribute is ommited, the new child is appended as the last child of the selected context node.

The xupdate:append element may contain the following types of elements:

  • xupdate:element
  • xupdate:attribute
  • xupdate:text
  • xupdate:processing-instruction
  • xupdate:comment

The meaning of these elements is described above.

For example, this


 <xupdate:append select="/addresses" child="last()"> 
   <xupdate:element name="address"> 
     <town>San Francisco</town> 
   </xupdate:element> 
 </xupdate:append>  

would append the new address element as the last child of addresses


 <addresses> 
   <address>
     <town>Los Angeles</town> 
   </address>
   <address> 
     <town>San Francisco</town> 
   </address>
 </addresses>

Update

The xupdate:update element can be used to update the content of existing nodes. An xupdate:update element must have a select attribute, which selects the context node for update. This select expression must evaluate to a node-set.

For example, this


 <xupdate:update select="/addresses/address[2]/town"> 
   New York 
 </xupdate:update> 

would change the content of the context node to


 <addresses> 
   <address>
     <town>Los Angeles</town> 
   </address>
   <address> 
     <town>New York</town> 
   </address>
 </addresses>

Remove

The xupdate:remove element allows a node to be removed from the result tree. The xupdate:remove element has a required select attribute, which specifies the node selected by an XPath expression. The select expression must evaluate to a node-set.

For example, this


 <xupdate:remove select="/addresses/address[1]"/> 

would remove the first occurence of address to


 <addresses>
   <address> 
     <town>New York</town> 
   </address>
 </addresses>

Rename

The xupdate:rename element allows an attribute or element node to be renamed after its creation. The xupdate:rename element has a required select attribute, which specifies the node selected by an XPath expression. The select expression must evaluate to a node-set of element or attribute nodes. It is an error if any other node type should be renamed.

For example, this


 <xupdate:rename select="/addresses/address/town"> 
   city 
 </xupdate:rename>

would rename the town child node of address to


 <addresses> 
   <address> 
     <city>New York</city> 
   </address>
 </addresses>

Variables and Values of Variables

A variable is a name that may be bound to a value. The value to which a variable is bound (the value of the variable) can be an object of any of the types that can be returned by expressions.

The xupdate:variable element has a required name attribute, which specifies the name of the variable.

For example, this


 <xupdate:variable name="town" select="/addresses/address[0]/town"/> 

 <xupdate:append select="/addresses"> 
   <xupdate:element name="address"> 
     <xupdate:value-of select="$town"/> 
   </xupdate:element> 
 </xupdate:append>

binds the selected object to the variable named town and uses the value of this variable to append a new address record.


 <xupdate:append select="/addresses"> 
   <xupdate:element name="address"> 
     <xupdate:value-of select="/addresses/address[0]/town"/> 
   </xupdate:element> 
 </xupdate:append>


Document Type Definition for XUpdate

The DTD for XUpdate is given below.


 <!ENTITY % commands "
     xupdate:variable
   | xupdate:insert-before
   | xupdate:insert-after
   | xupdate:append
   | xupdate:update
   | xupdate:remove
   | xupdate:rename
 ">

 <!ENTITY % instructions "
     xupdate:element
   | xupdate:attribute
   | xupdate:text
   | xupdate:processing-instruction
   | xupdate:comment
 ">

 <!ENTITY % qname "NMTOKEN"> 
 
 <!ENTITY % template " 
  (#PCDATA 
   | %instructions;)* 
 "> 

 <!ELEMENT xupdate:modifications (%commands;)*>
 <!ATTLIST xupdate:modifications 
    id          ID      #IMPLIED 
    version     NMTOKEN #REQUIRED
    xmlns:xupdate CDATA   #FIXED "http://www.xmldb.org/xupdate" 
 > 

 <!ELEMENT xupdate:insert-before (%instructions;)*>
 <!ATTLIST xupdate:insert
    select      CDATA   #REQUIRED
 >

 <!ELEMENT xupdate:insert-after (%instructions;)*>
 <!ATTLIST xupdate:insert
    select      CDATA   #REQUIRED
 >

 <!ELEMENT xupdate:append (%instructions;)*>
 <!ATTLIST xupdate:insert
    select      CDATA   #REQUIRED
    child       CDATA   #IMPLIED
 >

 <!ELEMENT xupdate:element %template;>
 <!ATTLIST xupdate:element
    name        %qname; #REQUIRED
    namespace   CDATA   #IMPLIED
 >

 <!ELEMENT xupdate:attribute (#PCDATA)>
 <!ATTLIST xupdate:attribute
    name        %qname; #REQUIRED
    namespace   CDATA   #IMPLIED
 >

 <!ELEMENT xupdate:text (#PCDATA)>

 <!ELEMENT xupdate:processing-instruction (#PCDATA)>
 <!ATTLIST xupdate:processing-instruction
    name        NMTOKEN #REQUIRED
 >
 
 <!ELEMENT xupdate:update (#PCDATA)>
 <!ATTLIST xupdate:update
    select      CDATA   #REQUIRED 
 >

 <!ELEMENT xupdate:remove EMPTY> 
 <!ATTLIST xupdate:remove 
    select      CDATA   #REQUIRED 
 > 

 <!ELEMENT xupdate:rename (#PCDATA)>
 <!ATTLIST xupdate:rename
    select      CDATA   #REQUIRED
 > 

 <!ELEMENT xupdate:variable (#PCDATA)*> 
 <!ATTLIST xupdate:variable 
    name        NMTOKEN #REQUIRED 
    select      CDATA   #IMPLIED 
 >

 <!ELEMENT xupdate:value-of EMPTY> 
 <!ATTLIST xupdate:value-of 
    select      CDATA   #REQUIRED 
 >

 <!ELEMENT xupdate:if %template;> 
 <!ATTLIST xupdate:if 
    test        CDATA   #REQUIRED 
 >


Example of Usage

This is an example of updating some data represented in XML using different XUpdate modifications to produce different results of the input data.

The input data is:


 <?xml version="1.0"?> 
 <addresses version="1.0"> 

   <address id="1"> 
     <fullname>Andreas Laux</fullname> 
     <born day='1' month='12' year='1978'/> 
     <town>Leipzig</town> 
     <country>Germany</country> 
   </address> 

 </addresses>

The following XUpdate update inserts a new address element after the first address.


 <?xml version="1.0"?> 
 <xupdate:modifications version="1.0"
                xmlns:xupdate="http://www.xmldb.org/xupdate"> 

   <xupdate:insert-after select="/addresses/address[1]" > 

     <xupdate:element name="address">
       <xupdate:attribute name="id">2</xupdate:attribute>
       <fullname>Lars Martin</fullname> 
       <born day='2' month='12' year='1974'/> 
       <town>Leizig</town> 
       <country>Germany</country> 
     </xupdate:element> 

   </xupdate:insert-after> 
 </xupdate:modifications> 

The XML result is


 <?xml version="1.0"?> 
 <addresses version="1.0"> 

     <address id="1"> 
       <fullname>Andreas Laux</fullname> 
       <born day='1' month='12' year='1978'/> 
       <town>Leipzig</town> 
       <country>Germany</country> 
     </address> 

     <address id="2"> 
       <fullname>Lars Martin</fullname> 
       <born day='2' month='12' year='1974'/> 
       <town>Leizig</town> 
       <country>Germany</country> 
     </address> 

 </addresses>

Open Issues

  • conditional processing of update commands

Normative References

  • [XML] "Extensible Markup Language (XML) 1.0", Tim Bray, Jean Paoli, C. M. Sperberg-McQueen, 10 February 1998
  • [XPath] "XML Path Language (XPath) Version 1.0", James Clark, Steve DeRose, 16 November 1999
  • [XSLT] "XSL Transformations (XSLT) Version 1.0", James Clark, 16 November 1999

Other References

  • [XEditor] "XML Editing Language (XEditor)", Jonathan Borden, August 2000


Copyright © 2000-2003 The XML:DB Initiative. All Rights Reserved.