Why to use unique, key and keyref XML Schema elements

/*
this mail is also attached as an plain ASCII text in English with \n only at the end of paragraphs and \t formated XML document
*/

Dear W3C Schema developers! 

I have been asked by one of Your member (or W3C member) participated on XML Schema RFC to write to You why and how I want to use <unique/>, <key/> and <keyref/> elements, because You have not received enough feedbacks to these elements. 

At first - I am very glad You have developed something like XML Schema. It looks much more better, readable etc. than DTD. 

Because I am developing web applications mostly based on relational (SQL) databases, I want to use XML for machine2user, machine2machine and user2machine exchange of database oriented data. So, properly created XML Schema should assure one of the principal database thing - DATABASE INTEGRITY (especialy in case of user2machine data exchange). 

How I imagine to utilize XML Schema? I know three types of database integrity (domain, entity, reference). Sorry, if I wrong translate integrity names into English. 

1) DOMAIN INTEGRITY 
This integrity XML Schema can assure much more better (or precise) than standard databases. It is clear - setting correct simple type for an element~attribute using standard or restricted datatype. 

2) ENTITY INTEGRITY 
For this type of integrity I need (as I think) XML Schema element <unique/>. This element should assure, that within the scope of each element~record e.g. <city/> all elements~attributes, which are simple or complex primary key are unique e.g. <city_id>, <district_id>. Or, in general, in case of not setting of primary key of the table, which is not very common, all elements~attributes as the whole have to be unique. I have not found any other way to ensure that with XML Schema than <unique/>. So this is the purpose I found <unique/> essential. 

3) REFERENCE INTEGRITY
For this type of integrity I need (as I think) XML Schema element <key/> and <keyref/>. These elements  should assure, that one element~attribute inside its element~record is unique and can be referenced from another element~attribute inside its element~record. 

For a better explanation see a small XML document which is an dump of a database simplified for purpose of this mail.

<dbxv_chs_tree_query>
 <OBLAST>
  <OBLAST.id_oblast>001</OBLAST.id_oblast>
  <nazev_oblast>Suche skaly</nazev_oblast>
  <email>stepan.rybar@ceu.cz</email>
  <SKALA>
   <SKALA.id_oblast>001</SKALA.id_oblast>
   <SKALA.id_skala>001</SKALA.id_skala>
   <nazev_skala>Prvni vez</nazev_skala>
   <CESTA>
    <CESTA.id_oblast>001</CESTA.id_oblast>
    <CESTA.id_skala>001</CESTA.id_skala>
    <CESTA.id_cesta>01</CESTA.id_cesta>
    <nazev_cesta>Jihozapadni hrana</nazev_cesta>
   </CESTA>
   <CESTA>
    <CESTA.id_oblast>001</CESTA.id_oblast>
    <CESTA.id_skala>001</CESTA.id_skala>
    <CESTA.id_cesta>02</CESTA.id_cesta>
    <nazev_cesta>Hopsava</nazev_cesta>
   </CESTA>
  </SKALA>
 </OBLAST>
</dbxv_chs_tree_query>

What should XML Schema assure:

1) Domain integrity 
a) <OBLAST.id_oblast/> has to be restricted to string containing numerical characters (string -> RegExp pattern)
n) etc.

2) Entity integrity 
a) <OBLAST.id_oblast/> has to be unique within one instance of  <dbxv_chs_tree_query/> 
b) (<SKALA.id_oblast/> and <SKALA.id_skala/>) has to be unique within one instance of <SKALA/>,  
c) (<CESTA.id_oblast/> and <CESTA.id_skala/> and <CESTA.id_cesta/>) has to be unique within one instance of <CESTA/>

3) Reference integrity 
a) <OBLAST.id_oblast/> has to be able to be referenced by <SKALA.id_oblast/> and <CESTA.id_oblast/>, which have their parent value 
b) <SKALA.id_skala/> has to be able to be referenced by  <CESTA.id_oblast/>, which have their parent value 


Well, I hope, I have explained need of elements <unique/>, <key/> and <keyref/> in XML Schema RFC. If I have made any error or misunderstood XML Schema purpose, I am apologized for that. In case something is unclear in my mail, please, feel free to e-mail me for an explanation. Because I can not receive mails from this listserver group, if will be any need, contact me also via my e-mail address.


Stepan Rybar, "stepan.rybar@ceu.cz"

department of information technology 
the Czech Environmental Institute 
Prague, the Czech Republic, Europe

Received on Friday, 19 January 2001 09:45:00 UTC