XML:DB Home

Index
Working Draft
API
Online Demo
Orig. Proposal

Repository

Mail List
Mail Archive
Authors
Dare Obasanjo - kpako@yahoo.com
Status
Working Draft - 2002-04-20
Notice
This is a 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. Comments on this specification should be sent to SiXDML mailing list sixdml-dev@xmldb.org.
Abstract
XML has become a popular data interchange and storage format which in recent times has precipitated the rise of XML-enabled relational databases as well as native XML databases. In the relational database world there exist programming APIs as well as a single language that provides a single point from which to perform data definition, manipulation and management tasks within the database management system. Unfortunately nothing analogous to such a language (SQL) or such APIs(ODBC, JDBC, etc) exist for XML databases. This document outlines a data manipulation language for XML repositories that enables users to perform data management tasks such as creation and deletion of indices, collections and documents. The language proposed also provides the ability to perform queries, transformations and updates on the documents in the XML repository either singly or across an entire collection. Syntax for the language borrows heavily from SQL and DL/I so as to be familiar to developers and DBAs already familiar with relational and hierarchical database systems.

Table of Contents


1 Introduction
2 Terminology
    2.1 Document
    2.2 Collection
    2.3 Schema
    2.4 Index
    2.5 XML Repository
    2.6 Query Processor
3 Syntax and Semantics of SiXDML
    3.1 CREATE COLLECTION Statement
        3.1.1 Sample Queries
    3.2 SHOW COLLECTION Statement
        3.2.1 Sample Queries
    3.3 DROP COLLECTION Statement
        3.3.1 Sample Queries
    3.4 INSERT INTO COLLECTION Statement
        3.4.1 Sample Queries
    3.5 DROP FROM COLLECTION Statement
        3.5.1 Sample Queries
    3.6 CONSTRAIN COLLECTION Statement
        3.6.1 Sample Queries
    3.7 DROP CONSTRAINTS Statement
        3.7.1 Sample Queries
    3.8 SHOW CONSTRAINTS Statement
        3.8.1 Sample Queries
    3.9 CREATE INDEX Statement
        3.9.1 Sample Queries
    3.10 DROP INDEX Statement
        3.10.1 Sample Queries
    3.11 SHOW INDEX Statement
        3.11.1 Sample Queries
    3.12 SHOW INDEXES Statement
        3.12.1 Sample Queries
    3.13 NAMESPACE Statement
        3.13.1 Sample Queries
    3.14 SELECT Statement
        3.14.1 Sample Queries
    3.15 INSERT BEFORE Statement
        3.15.1 Sample Queries
    3.16 INSERT INTO Statement
        3.16.1 Sample Queries
    3.17 INSERT AFTER Statement
        3.17.1 Sample Queries
    3.18 INSERT ATTRIBUTE Statement
        3.18.1 Sample Queries
    3.19 DELETE Statement
        3.19.1 Sample Queries
    3.20 REPLACE Statement
        3.20.1 Sample Queries
    3.21 RENAME Statement
        3.21.1 Sample Queries
4 Known Issues
5 SiXDML Grammar
6 Bibliography
7 Acknowledgements

Appendices



Introduction

The need for a single mechanism that allows programmers and regular users alike the means to manipulate the documents and collections is highlighted by the fact that currently most native XML databases as well as XML-enabled databases provide multiple means to perform sets of interrelated tasks that can be done via single mechanism in a relational or hierarchical database. It is not uncommon to see a native XML database that uses XPath for querying, an XML-based language or XML Document Object Model (DOM) interaction for updates, and a graphical or command line interface for managing documents and collections.

SiXDML was designed to create a common syntax and semantics for performing tasks most often required of XML repositories. SiXDML consists of two parts; a data definition and manipulation language inspired by SQL and an application programming interface based on the XML:DB Database API.

The SiXDML language is designed to be easily understood by programmers and non-programmers alike, internet-aware, and combine a minimum of complexity with a maximum of functionality while being straight-forward to implement. SiXDML aims to plug the hole that currently exists for a data manipulation language that allows one to query and update XML documents while also providing a means to perform database management activities. Although numerous query languages exist for XML including Lorel, Quilt, UnQL, XDuce, XML-QL, XPath, XQL, XQuery and YaTL yet no popularly accepted XML query language possesses data manipulation semantics such as DELETE, REPLACE and INSERT that exist in a relational data manipulation language like SQL or a hierarchical data manipulation language like DL/I.

XQuery which seems set to become the standard query language for XML repositories does not have update semantics in the December 2001 draft although some investigation on how to add updates to XQuery have been carried out by researchers like Patrick Lehti and vendors like Microsoft and Software AG. The XQuery working group has hinted that a version of XQuery that contains updates is about a year or more away. However, proposals for a language that also allows one to manage indices, collections and schemas in an XML repository in the same manner one can manage indexes, triggers and relations in a relational database with SQL have not been forthcoming.


Terminology

In this section, some concepts and terminology from the realm of XML databases which are a basic part of the framework upon which SiXDML is built are described.

Document

A document is considered to be a well-formed and optionally valid XML document that can be stored in an XML repository.


Collection

A collection contains a group of XML documents which may optionally conform to a single schema and can be queried and updated simultaneously by a single SiXDML statement. To SiXDML, a collection is akin to a directory on a filesystem that contains XML documents. A homogenous collection whose documents conform to one or more schemata can be considered to be akin to a row in relational table.


Schema

A schema is a document that is used to specify constraints on the XML documents in a particular collection. SiXDML is not designed with any specific schema technology given special consideration and instead will rely upon implementations to specify what schema technologies will be used or supported. Thus DTDs, W3C XML schema, XDR files and RELAX NG documents can all be supported by an XML repository that uses SiXDML.


Index

In many XML repositories, query performance can be improved by specifying certain elements, attributes or access patterns that should be indexed. Different repositories have different indexing capabilities; some like eXcelon's XIS allow one to index each individual word in an element (via a text index), the text value of each element (via a value index), or the expected node structure that will be returned by the query (via a structure index).

The design of SiXDML takes into consideration the fact that many different indexing techniques for XML data exist.


XML Repository

An XML repository is a storage system, preferably one that supports ACID transactions, that manages XML documents and controls access to them. Native XML databases, XML content management systems and XML-enabled databases are all examples of XML repositories.


Query Processor

The query processor accepts SiXDML syntax, parses it and executes the query against the XML repository. It is expected that the query processor is capable of performing optimizations to improve performance of queries before executing them.



Syntax and Semantics of SiXDML

SiXDML is designed with familiarity in mind and thus borrows heavily from the syntax of SQL and DL/I for its keywords. Similarly, SiXDML uses XPath for performing queries due to its widespread popularity and relative simplicity. Since one of the goals of SiXDML is to provide a language that is easily understood by programmers and non-programmers alike programming constructs like variable declarations, bound variables, functions, and nested queries have been avoided. The combination of using XPath for queries and the ability to pipe the results of a SELECT statement to a filter such as an XSLT stylesheet or an XQuery expression makes the effects of a lack of sophisticated programming constructs in SiXDML minimal. An XML syntax for SiXDML, similar to that used for XUpdate, was considered and discarded because it would have added to the complexity of the language by making it unnecessarily verbose as well as unfamiliar to adopters of the language.

CREATE COLLECTION Statement

CreateStatement     ::=     'CREATE'   CreateCollectionClause
 
CreateCollectionClause     ::=     CollectionClause ( 'CONSTRAINED BY' URL )?
 

The above command creates a collection with the specified path and optionally specifies the schema that will be used to constrain the documents in the collection. The schema can be located over the internet or on a local filesystem.

Sample Queries

  1. CREATE COLLECTION bookstore
    Create a collection at the top level of the repository named "bookstore". This command fails if the bookstore collection already exists

  2. CREATE COLLECTION bookstore/out_of_stock
    Create a subcollection of the bookstore collection named "out_of_stock". This command fails if the there is no bookstore collection.

  3. CREATE COLLECTION bookstore CONSTRAINED BY http://www.25hoursaday.com/books.xsd
    Create a collection at the top level of the repository named "bookstore" and specify that only documents that validate against the schema obtained from http://www.25hoursaday.com/books.xsd can be stored in the collection. This command fails if the bookstore collection already exists or if the schema could not be retrieved.





SHOW COLLECTION Statement

ShowStatement     ::=     'SHOW' CollectionClause  

Lists the contents of the collection, which should typically be documents and/or subcollections. The contents of the collection should either be displayed as XML that conforms to the W3C XML schema below or as text that contains at least the same amount of information as would be shown in the XML version.

 
 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
            xmlns="xmlns://www.sixdml.org/2002/04/language/" 
            elementFormDefault="qualified"
            targetNamespace="xmlns://www.sixdml.org/2002/04/language/"> 

   <xs:element name="collection-contents" type="collectionContentsType"/> 

   <xs:complexType name="collectionContentsType">
     <xs:choice maxOccurs="unbounded">
       <xs:element name="document"  type="namedItem"/>
       <xs:element name="collection" type="namedItem"/>
     </xs:choice>
   </xs:complexType>

   <xs:complexType name="namedItem">
     <xs:simpleContent>
       <xs:extension base="xs:string">
         <xs:attribute name="name" type="xs:string" />
       </xs:extension>
     </xs:simpleContent>  
   </xs:complexType>

 </xs:schema>

Sample Queries

  1. SHOW COLLECTION bookstore
    Lists the names of the documents and subcollections in the bookstore collection

  2. SHOW COLLECTION /
    Lists the names of the documents and subcollections in the root (top-level) collection

  3. SHOW COLLECTION records/april95
    Lists the names of the documents and subcollections in the april95 subcollection of the records collection





DROP COLLECTION Statement

DropStatement     ::=     'DROP' CollectionClause 

Deletes a collection and all its children from the repository.

Sample Queries

  1. DROP COLLECTION bookstore
    Deletes the bookstore collection and any documents or subcollections that were contained within it.





INSERT INTO COLLECTION Statement

InsertStatement     ::=     'INSERT'
(    InsertXmlClause
   |   InsertDocumentClause)
 
InsertDocumentClause     ::=     URL 'INTO' CollectionClause  
InsertXmlClause     ::=     InlineXml 'NAMED' DocumentName 'INTO' CollectionClause
 

Adds a new document to the specified collection. If there is a schema constraining this collection, the document must be valid against the schema for this operation to succeed.

Sample Queries

  1. INSERT http://www.25hoursaday.com/books.xml INTO COLLECTION bookstore
    Insert the document named books.xml obtained from the provided URL into the bookstore collection. This command fails if the bookstore collection does not exist, there was an error retrieving the document or a if a document named books.xml already exists in the database. If a schema exists for the bookstore collection and books.xml does not conform to the schema then the insertion attempt fails.

  2. INSERT{
    <bk:bookstore xmlns:bk="urn:bookstore-schema">
    <bk:book genre="Fantasy">
    <bk:title>The Hobbit</bk:title>
    <bk:author>
    <bk:first-name>J.R.R.</bk:first-name>
    <bk:last-name>Tolkien</bk:last-name>
    </bk:author>
    <bk:price>14.99</bk:price>
    </bk:book>
    </bk:bookstore>
    }
    NAMED fantasy-books.xml INTO COLLECTION bookstore;

    Insert the document named fantasy-books.xml obtained from the inlined XML into the bookstore collection. This command fails if the inlined XML is not well formed, bookstore collection does not exist, there was an error retrieving the document or a if a document named fantasy-books.xml already exists in the database. If a schema exists for the bookstore collection and books.xml does not conform to the schema then the insertion attempt fails.



DROP FROM COLLECTION Statement

DropStatement     ::=     'DROP' DocumentPath 'FROM' CollectionClause
 

Removes a document from the collection.

Sample Queries

  1. DROP penguin_books.xml FROM COLLECTION bookstore/out_of_stock
    Removes the document named penguin_books.xml from the out_of_stock subcollection of the bookstore collection.



CONSTRAIN COLLECTION Statement

ConstrainStatement     ::=     'CONSTRAIN' CollectionClause 'WITH' URL  

Specifies the schema that will be used to constrain a collection. Every document in the collection must validate against the schema or the operation fails. If there is already a schema constraining this collection it must be replaced if all documents validate against the new schema.

Sample Queries

  1. CONSTRAIN COLLECTION bookstore WITH http://www.25hoursaday.com/books.xsd
    Retrieve the schema named books.xsd from the URL and validates every document in the collection against it. If all validations are successful then the retrieved document becomes the schema for the collection. This command fails if the bookstore collection does not exist, there was an error retrieving the schema or a if a document in the bookstore collection that does not conform to the schema.



DROP CONSTRAINTS Statement

DropStatement     ::=     'DROP CONSTRAINTS ON' CollectionClause  

Deletes the schema that constrains the contents of a particular collection.

Sample Queries

  1. DROP CONSTRAINTS ON COLLECTION bookstore
    Delete the schema associated with the bookstore collection if one exists. Thus documents inserted after this command has been executed do not have to be valid against the schema just well-formed XML documents.



SHOW CONSTRAINTS Statement

ShowStatement     ::=     'SHOW CONSTRAINTS ON' CollectionClause  

Displays the schema for the specified collection, if any.

Sample Queries

  1. SHOW CONSTRAINTS ON COLLECTION bookstore
    Displays the schema associated with the bookstore collection if one exists.



CREATE INDEX Statement

CreateStatement     ::=     'CREATE' CreateIndexClause  
CreateIndexClause     ::=     IndexClause 'OF TYPE' Nmtoken 'WITH KEY =' XPathExpression (',' KeyValuePair)* 'ON ' CollectionClause  

Creates an index on a particular attribute or element in a document. The key is the value that will be searched against while the optional list of key value pairs is contains parameters that are dependent on the type of index. The XPath expressions are subsets of XPath 1.0.

NOTE: Index names should not have to be unique across collections. This may be an onerous burden on some implementations so thus is not mandatory.

Sample Queries

  1. CREATE INDEX author-lastname-idx OF TYPE STRUCTURE_INDEX WITH KEY=/author/last-name, ELEMENT=/author ON COLLECTION bookstore ;
    Creates a structure index on each document in the bookstore collection named "author-lastname-idx". Searches which involves queries on the <last-name> child of the <author> element which return an <author> element are optimized by this index. This operation fails if the database does not support structure indices.

  2. CREATE INDEX person-name-idx OF TYPE VALUE_INDEX WITH KEY=/document/person/@name ON COLLECTION bookstore ;
    This indexes the values of the name attribute of a <person> element in documents within the bookstore collection. This operation fails if the database does not support value indices.



DROP INDEX Statement

DropStatement     ::=     'DROP' IndexClause 'FROM' CollectionClause  

Removes the specified index.

Sample Queries

  1. DROP INDEX val-index FROM COLLECTION bookstore
    Removes the value index named val-index that applies to every document in the bookstore collection.



SHOW INDEX Statement

ShowStatement     ::=     'SHOW' IndexClause 'ON' CollectionClause  

Lists the name, type, and index fields of an index that applies to a particular collection. The index on the collection should either be displayed as XML that conforms to the W3C XML schema below or as text that contains at least the same amount of information as would be shown in the XML version.


 <xs:schema targetNamespace="xmlns://www.sixdml.org/2002/04/language/" 
            xmlns:sixdml="xmlns://www.sixdml.org/2002/04/language/" 
            elementFormDefault="qualified" 
            xmlns:xs="http://www.w3.org/2001/XMLSchema">

   <xs:element name="index" minOccurs="0" maxOccurs="unbounded">
     <xs:complexType>
       <xs:sequence>
         <xs:element name="name" type="xs:string" />
         <xs:element name="type" type="xs:string" />
         <xs:element name="key" type="xs:string" />
         <xs:any namespace="##any" processContents="lax" minOccurs="0" 
                 maxOccurs="unbounded" />
       </xs:sequence>
       <xs:attribute name="collection" type="xs:string" />
     </xs:complexType>
   </xs:element>  

</xs:schema> 

Sample Queries

  1. SHOW INDEX book-title-idx ON COLLECTION bookstore
    Displays information on index named "book-title-idx" that applies to the bookstore collection. If the index does not exist then an error message is shown.



SHOW INDEXES Statement

ShowStatement     ::=     'SHOW INDEXES ON' CollectionClause  

Lists the name, type, and index fields of every index that applies to a particular collection. The indices on the collection should either be displayed as XML that conforms to the W3C XML schema below or as text that contains at least the same amount of information as would be shown in the XML version.


 <xs:schema targetNamespace="xmlns://www.sixdml.org/2002/04/language/"  
            xmlns:sixdml="xmlns://www.sixdml.org/2002/04/language/" 
            elementFormDefault="qualified" 
            xmlns:xs="http://www.w3.org/2001/XMLSchema">

   <xs:element name="indexes">
     <xs:complexType>
       <xs:sequence>
         <xs:element name="index" minOccurs="0" maxOccurs="unbounded">
           <xs:complexType>
             <xs:sequence>
               <xs:element name="name" type="xs:string" />
               <xs:element name="type" type="xs:string" />
               <xs:element name="key" type="xs:string" />
               <xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded" /> 
             </xs:sequence>
           </xs:complexType>
         </xs:element>
       </xs:sequence>
       <xs:attribute name="collection" type="xs:string" />
     </xs:complexType>
   </xs:element>

</xs:schema> 

Sample Queries

  1. SHOW INDEXES ON COLLECTION bookstore
    Displays information on all the indices that apply to the bookstore collection, if any.



NAMESPACE Statement

NamespaceDecl     ::=     'NAMESPACE' NCName '=' URI  

A namespace declaration defines a namespace prefix and associates it with a namespace URI. The namespace URI must be a valid URI, and must not be an empty string. The namespace declaration must be in scope for the rest of the SiXDML query or until the prefix is paired with another namespace. It is likely that for interactive sessions, implementations may want to alter the lifetime of a namespace declaration to beyond single queries. Lifetime of namespace declarations outside of a query's scope is dependent on implementations.

Sample Queries

  1. NAMESPACE xsl = "http://www.w3.org/1999/XSL/Transform"
    This binds the prefix "xsl" to the XSLT namespace.



SELECT Statement

SelectStatement     ::=     'SELECT' XPathExpression 'FROM' (CollectionClause (WhereClause)? | DocumentPath)
('USING ROOT =' QName)? (   'AND TRANSFORM WITH' ('XSLT' | 'XQUERY' | 'XPATH'| Nmtoken) 'IN' (URL | InlineXml)   )?  

Executes the XPath query on the document or collection and optionally sends the results to the query or stylesheet, which is declared inline for further processing. The results of executing the query [before additional processing] are returned as XML that conforms to the following schema

	 
 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
            xmlns="http://www.25hoursaday.com/sixdml/"
            elementFormDefault="qualified"
            targetNamespace="http://www.25hoursaday.com/sixdml/"> 

   <xs:element name="query-results" type="queryResultsType"/>

   <xs:complexType name="queryResultsType">
     <xs:sequence maxOccurs="unbounded">
       <xs:element name="query-result"  type="queryResultType"/> 
     </xs:sequence>
     <xs:attribute name="collection-name" type="xs:string"/>
     <xs:attribute name="query" type="xs:string" use="required" />
     <xs:attribute name="predicate" type="xs:string" use="optional" />
   </xs:complexType>

   <xs:complexType name="queryResultType" mixed="true">
     <xs:sequence>
       <xs:any minOccurs="0" maxOccurs="unbounded"
               processContents="skip"/>
     </xs:sequence>
     <xs:attribute name="resource-name" type="xs:string"/>
   </xs:complexType>

 </xs:schema>

Sample Queries

  1. SELECT //tr FROM auctiondata/sort-bidder-.xsl
    Select every <tr> element in the sort-bidder-.xsl document in the auctiondata collection. The result is returned as a series of <tr> elements which is non-well formed if more than one <tr> element was found.

  2. NAMESPACE bk: = "urn:my-bookstore"
    SELECT //bk:title FROM COLLECTION bookstore

    Select every title
    element from the "urn:my-bookstore" namespace in every document within the bookstore collection.

  3. NAMESPACE bk: = "urn:my-bookstore"
    SELECT count(//bk:book) FROM bookstore/my-books.xml USING ROOT=total-num-books

    Returns the total number of book
    elements from the "urn:my-bookstore" namespace that are in the my-books.xml document within the bookstore collection. The number returned by the query is wrapped by <total-num-books> tags.

  4. NAMESPACE bk: = "urn:my-bookstore"
    SELECT count(//bk:book) FROM COLLECTION bookstore WHERE count(//bk:book) > 0

    Returns the total number of book
    elements from the "urn:my-bookstore" namespace for each document within the bookstore collection that has at least one book
    element.

  5. SELECT //TITLE[text()='Sandstone'] FROM
    auctiondata/auction1.xml AND TRANSFORM WITH XSLT IN{

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">
    <xsl:template match="/">
    <HTML>
    <HEAD><TITLE><xsl:value-of select='/document/title'/></TITLE></HEAD>
    <BODY><xsl:apply-templates/></BODY>
    </HTML>
    </xsl:template>

    <xsl:template match="TITLE">
    <H1><xsl:apply-templates/></H1>
    </xsl:template>

    </xsl:stylesheet>
    }

    Select every <TITLE> element from the auction1.xml document in the auctiondata collection that contains the text "SandStone" and passes the results to the inlined XSLT stylesheet. If there is more than one <TITLE> element the XSLT processor will complain because the XML passed to it is not well-formed. The query thus fails if the XML returned by the XPath query is not well-formed.This query fails if there is a problem with the well-formedness or validity of the inlined XSLT stylesheet.

  6. SELECT //TITLE[text()='Sandstone'] FROM auctiondata/auction1.xml AND TRANSFORM WITH XSLT IN http://www.25hoursaday.com/title.xsl
    Select every <TITLE> element from the auction1.xml document in the auctiondata collection that contains the text "SandStone" and passes the results to the specified XSLT stylesheet. If there is more than one <TITLE> element the XSLT processor will complain because the XML passed to it is not well-formed. The query thus fails if the XML returned by the XPath query is not well-formed. This query fails if there is a problem retrieving the XSLT stylesheet from the URL, and if there are issues with the well-formedness or validity of the inlined XSLT stylesheet.



INSERT BEFORE Statement

InsertStatement     ::=     'INSERT' InsertXmlClause  
InsertXmlClause     ::=     InlineXml 'BEFORE' XPathExpression 'IN' (CollectionClause (WhereClause)? | DocumentPath)
 

Inserts an xml document fragment, processing instruction, comment, text , CDATA section or any combination thereof before all nodes that match the expression. The data to be inserted is declared inline in regular XML syntax. The XPath expression is an Xpath 1.0 expression that must result in one or more comment, processing-instruction, text, element nodes to be valid. The operation must fail if the target node is the document root and an attempt is made to insert anything besides comments or processing instructions.

Sample Queries

  1. INSERT{

    <!-- The following element is a book -->

    } BEFORE //bk:book IN bookstore/books.xml

    Inserts the comment "The following element is a book" before each <bk:book> element in the books.xml document in the bookstore collection.

    NOTE: The XPath query used above assumes that the underlying XML repository allows one to query based only on qualified names without taking namespaces into consideration. Although many current XPath engines allow one to do this, it is not completely compliant with the ideas in the the XML namespaces spec.



INSERT INTO Statement

InsertStatement     ::=     'INSERT' InsertXmlClause  
InsertXmlClause     ::=     InlineXml 'INTO' XPathExpression 'IN' (CollectionClause (WhereClause)?| DocumentPath)
 

Inserts an xml document fragment, processing instruction, comment, text ,CDATA section or any combination thereof as a child of each node that match the expression. The data to be inserted is declared inline in regular XML syntax. The XPath expression is an XPath 1.0 expression that must fail if the results of the query are not one or more element nodes.

Sample Queries

  1. INSERT{

    <bk:book xmlns:bk="urn:bookstore-schema" genre="Fantasy/Comedy">
    <bk:title>Men At Arms</bk:title>
    <bk:author>
    <bk:first-name>Terry</bk:first-name>
    <bk:last-name>Pratchett</bk:last-name>
    </bk:author>
    <bk:price>8.99</bk:price>
    </bk:book>

    } INTO //bk:bookstore IN COLLECTION bookstore

    Inserts the new <bk:book> element as a child of every <bk:bookstore> element in the bookstore collection.

    NOTE: The XPath query used above assumes that the underlying XML repository allows one to query based only on qualified names without taking namespaces into consideration. Although many current XPath engines allow one to do this, it is not completely compliant with the ideas in the the XML namespaces spec.



INSERT AFTER Statement

InsertStatement     ::=     'INSERT' InsertXmlClause  
InsertXmlClause     ::=     InlineXml 'AFTER' XPathExpression 'IN' (CollectionClause (WhereClause)? | DocumentPath)
 

Inserts an xml document fragment, processing instruction, comment, text, CDATA section or any combination thereof after all nodes that match the expression. The data to be inserted is declared inline in regular XML syntax. The XPath expression is an Xpath 1.0 expression that must result in one or more comment, processing-instruction, text, element nodes to be valid. The operation must fail if the target node is the document root and an attempt is made to insert anything besides comments or processing instructions.

Sample Queries

  1. INSERT{

    <bk:book xmlns:bk="urn:bookstore-schema" genre="Fantasy/Comedy">
    <bk:title>Interesting Times</bk:title>
    <bk:author>
    <bk:first-name>Terry</bk:first-name>
    <bk:last-name>Pratchett</bk:last-name>
    </bk:author>
    <bk:price>8.99</bk:price>
    </bk:book>

    } AFTER /bk:bookstore/bk:book[1] IN COLLECTION bookstore

    Inserts the new <bk:book> element after the first <bk:book> element that is a child of a <bk:bookstore> element for every document in the bookstore collection.

    NOTE: The XPath query used above assumes that the underlying XML repository allows one to query based only on qualified names without taking namespaces into consideration. Although many current XPath engines allow one to do this, it is not completely compliant with the ideas in the the XML namespaces spec.



INSERT ATTRIBUTE Statement

InsertStatement     ::=     'INSERT' InsertAttributeClause
 
InsertAttributeClause     ::=     'ATTRIBUTE WITH NAME =' QName ', VALUE=' AttValue 'INTO' XPathExpression 'IN' (CollectionClause (WhereClause)? | DocumentPath)  

Inserts an attribute at the specified position for all nodes that match the XPath expression. If a namespace URI is provided then it is expected that the name provided is an XML qualified name. If an attribute with the same name already exists at that position then its value is overwritten. The XPath expression is an XPath 1.0 expression that must result in one or more element nodes to be valid.

Sample Queries

  1. INSERT ATTRIBUTE WITH NAME="location", VALUE="Atlanta" INTO //book IN bookstore/fantasy-books.xml
    Inserts an attribute named location with the value "Atlanta" into every <book> element in the fantasy-books.xml document in the bookstore collection.

  2. NAMESPACE bk = "urn:bookstore-schema"
    NAMESPACE inv = "urn:inventory-schema"
    INSERT ATTRIBUTE WITH NAME="inv:status", VALUE="available" INTO //bk:book IN COLLECTION bookstore

    Inserts an attribute named status with namespace prefix "inv", namespace URI "urn:inventory-schema" and the value "available" into every <bk:book> element in the bookstore collection.



DELETE Statement

DeleteStatement     ::=     'DELETE ' XPathExpression 'FROM' (CollectionClause (WhereClause)? | DocumentPath)  

Removes all nodes that match the XPath expression.

Sample Queries

  1. DELETE //comment() FROM COLLECTION bookstore
    Deletes every comment in every document in the bookstore collection.

  2. DELETE /bk:bookstore/bk:book/bk:price FROM COLLECTION bookstore
    Deletes the <bk:price> element for all <bk:book> elements that are children of the root, <bk:bookstore> in the bookstore collection.

    NOTE: The XPath query used above assumes that the underlying XML repository allows one to query based only on qualified names without taking namespaces into consideration. Although many current XPath engines allow one to do this, it is not completely compliant with the ideas in the the XML namespaces spec.



REPLACE Statement

ReplaceStatement     ::=     'REPLACE' XPathExpression 'WITH' InlineXml 'IN' (CollectionClause (WhereClause)? | DocumentPath)  

Replaces one or more element, processing-instruction, comment, or text nodes with one or more of the same. The data to be inserted is declared inline in regular XML syntax. The XPath expression is an XPath 1.0 expression that must result in one or more comment, processing-instruction, text, element nodes to be valid.

Sample Queries

  1. REPLACE //bk:price WITH{

    <bk:price xmlns:bk="urn:bookstore-schema">Unavailable</bk:price>
    <![CDATA[ Prices are being reduced by 20% or 25% if > $10 ]]>
    <bk:rating xmlns:bk="urn:bookstore-schema" >9/10</bk:rating>

    } IN COLLECTION bookstore/books.xml

    Replaces every <bk:price> element with the a new <bk:price> element, a CDATA section and a <bk:rating> element. Note that each element added has its own namespace declaration(s).

    NOTE: The XPath query used above assumes that the underlying XML repository allows one to query based only on qualified names without taking namespaces into consideration. Although many current XPath engines allow one to do this, it is not completely compliant with the ideas in the the XML namespaces spec.



RENAME Statement

RenameStatement     ::=     'RENAME ' XPathExpression 'TO' QName 'IN' (CollectionClause (WhereClause)? | DocumentPath)  

This alters the name of the node(s) returned by the XPath expression to the one specified. The XPath expression is an XPath 1.0 expression that must result in one or more attribute or element nodes to be valid.

Sample Queries

  1. NAMESPACE bk = "urn:bookstore-schema"
    RENAME //bk:bookstore TO library IN bookstore/books.xml

    Change every <bk:bookstore> element in the document books.xml in the bookstore collection to a <library> element without altering its child nodes or attributes. However, the previous namespace information is discarded.

  2. NAMESPACE bk = "urn:bookstore-schema"
    RENAME //library TO bk:bookstore IN bookstore/books.xml

    Change every <library> element in the document books.xml in the bookstore collection to a <bk:bookstore> element without altering its child nodes or attributes. The previous namespace information is discarded, and the "bk" prefix is mapped to the "urn:bookstore-schema" namespace.

    NOTE: The XPath queries used above assume that the underlying XML repository allows one to query based only on qualified names without taking namespaces into consideration. Although many current XPath engines allow one to do this, it is not completely compliant with the ideas in the the XML namespaces spec.

  3. RENAME //@genre TO section IN COLLECTION bookstore
    Rename every attribute with the name "genre" in every document in the bookstore collection to "section" while keeping its value the same.




Known Issues

KNOWN ISSUE 1: The ability to perform joins and combine the results of one or more queries on different documents is a feature that some would like but there is difficulty in determining what syntax or semantics to use for specifying joins in SiXDML. A suggestion by Kimbro Staken involves performing queries like SELECT //node FROM /some/collection AS $x, //other-node FROM /some/other/collection as $y WHERE $x/value = $y/value.
The problem is the results end up being two trees with no clean way to merge them. Research into alternate syntax and semantics for joins is ongoing and suggestions would be welcome.


SiXDML Grammar

SixdmlQuery     ::=     (SixdmlStatement)+ 
SixdmlStatement     ::=     (NamespaceDecl)+    ( CreateStatement
|   DropStatement
|   ConstrainStatement
|   InsertStatement
|   ShowStatement
|   SelectStatement
|   DeleteStatement
|   ReplaceStatement
|   RenameStatement)
 
NamespaceDecl     ::=     'NAMESPACE' NCName '=' URI  
CreateStatement     ::=     'CREATE'
(   CreateCollectionClause
   |   CreateIndexClause )
 
CreateCollectionClause     ::=     CollectionClause ( 'CONSTRAINED BY' URL )?
 
CreateIndexClause     ::=     IndexClause 'OF TYPE' Nmtoken 'WITH KEY =' XPathExpression (',' KeyValuePair)* 'ON ' CollectionClause  
KeyValuePair     ::=     Nmtoken '=' (Char)+  
DropStatement     ::=     'DROP'
(   CollectionClause
   | ( (DocumentPath |    IndexClause) 'FROM' )|
(   'CONSTRAINTS ON') CollectionClause)
)
 
ConstrainStatement     ::=     'CONSTRAIN' CollectionClause 'WITH' URL  
InsertStatement     ::=     'INSERT'
(    InsertXmlClause
   |   InsertDocumentClause
   |   InsertAttributeClause)
 
InsertDocumentClause     ::=     URL 'INTO' CollectionClause  
InsertXmlClause     ::=     InlineXml
( 'NAMED' DocumentName 'INTO' CollectionClause)
|    ( 'BEFORE' | 'INTO' | 'AFTER' ) XPathExpression 'IN' (CollectionClause (WhereClause)? | DocumentPath)
 
InsertAttributeClause     ::=     'ATTRIBUTE WITH NAME =' QName ', VALUE=' AttValue 'INTO' XPathExpression 'IN' (CollectionClause (WhereClause)? | DocumentPath)  
ShowStatement     ::=     'SHOW' ( (IndexClause | 'CONSTRAINTS' | 'INDEXES') 'ON')? CollectionClause  
SelectStatement     ::=     'SELECT' XPathExpression 'FROM' (CollectionClause (WhereClause)? | DocumentPath)
('USING ROOT =' QName)? (   'AND TRANSFORM WITH' ('XSLT' | 'XQUERY' | 'XPATH'| Nmtoken) 'IN' (URL | InlineXml)   )?  
RenameStatement     ::=     'RENAME ' XPathExpression 'TO' QName ( 'WITH NSURI =' NSName )? 'IN' (CollectionClause (WhereClause)? | DocumentPath)  
DeleteStatement     ::=     'DELETE 'XPathExpression 'FROM' (CollectionClause (WhereClause)? | DocumentPath)  
ReplaceStatement     ::=     'REPLACE' XPathExpression 'WITH' InlineXml 'IN' (CollectionClause (WhereClause)? | DocumentPath)  
IndexClause     ::=     'INDEX' Nmtoken 
CollectionClause     ::=     'COLLECTION' CollectionPath  
WhereClause     ::=     'WHERE' XPathExpression  
CollectionPath     ::=     Nmtoken ( '/'   Nmtoken )*  
DocumentPath     ::=     (CollectionPath '/' )? DocumentName
 
DocumentName     ::=     Nmtoken '.' Nmtoken  
InlineXml     ::=     '{' document |   ( Comment | PI | CDSect | Element | CharData)+ '}'  



Bibliography

  1. Boag, Scott et al. XQuery 1.0: An XML Query Language (Working Draft). 20 December 2001. < http://www.w3.org/TR/2001/WD-xquery-20011220 >

  2. Clark, James and Steve DeRose. XPath: XML Path Language (Version 1.0). 16 November 1999. < http://www.w3.org/TR/1999/REC-xpath-19991116 >

  3. Lehti, Patrick. Design and Implementation of a Data Manipulation Processor for an XML Query Language. August 2001 < http://www.lehti.de/beruf/diplomarbeit.pdf >

  4. Milo, Tova, Dan Suciu and Victor Vianu. Typechecking For XML Transformers. 2000. < http://www.cs.washington.edu/homes/suciu/files/_F1077508982.ps

  5. Noga, Alon et al. XML with Data Values: Typechecking Revisited. 2001. < http://www.cs.washington.edu/homes/suciu/files/_F267673258.ps >

  6. Staken, Kimbro. XML:DB Database API (Working Draft). 20 September 2001. < http://www.xmldb.org/xapi/xapi-draft.html >

  7. Laux, Andreas. XUpdate - XML Update Language. 14 September 2000. < http://www.xmldb.org/xupdate/xupdate-wd.html >

  8. Kapp, Dan and Joe F. Leben. IMS Programming Techniques: A Guide To Using DL/I. New York: Van Nostrand Reinhold. 1986.

  9. Date, C.J. An Introduction to Database Systems. Addison-Wesley. 1981.

  10. Elmasri, Ramez and Shamkant B. Navathe. Fundamentals of Database Systems. Addison-Wesley. 1999.


Acknowledgements

The following people contibuted ideas have gone into the design of SiXDML: Kimbro Staken, Tom Bradford, Mike Champion, Michael Rys, Sanjay Bhatia, Michael Brundage and Dr. Shamkant B. Navathe.


© 2002 Dare Obasanjo

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