OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

relax-ng message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [Elist Home]


Subject: Re: TREX TC minutes from 2001-04-19


Michael Fitzgerald wrote:

> 2. ID/IDREF (uniqueness constraints). DTDs and XML Schema both support
> them -- should TREX v1.0? Norm said he doesn't see how  we can't support
> identity constraints! James said it was not at all easy or not trivial to
> implement. [Murata-san said something about identity constraints in three
> grammars, but I did not catch what it was.] Revisit.

I do not remember what I said, but I probably mentioned Wenfei Fen's work

Recently, I spoke with Jerome Simeon.  I learned that there are three approaches.

1) ID/IDERF (as in XML DTD)

2) XPath (as in XML Schema)

3) Types and path expressions (as in UCM)

The first approach is very weak.  The second one is complicated.  In particular,
it is to difficult to ensure consistencies of key declarations.  The third 
approach appears to be powerful, and is described in "A Unified Constraint Model 
for XML (WWW 10)" (http://www.cis.temple.edu/~fan/papers/xml/ucm.ps.gz)

I rewrote an example of UCM in the TREX syntax.  Consider an XML document as 
below:

<data>
<companies>
  <company>
  <co>foo</co>
  <stock>10.3</stock>
  </company>
  <company>
  <co>bar</co>
  <stock>10.3</stock>
  </company>
</companies>
<depts>
  <dept>
  <dname>1</dname>
  <co>foo</co>
  <topic/>
  </dept>
  <dept>
  <dname>2</dname>
  <co>foo</co>
  <topic/>
  </dept>
  <dept>
  <dname>1</dname>
  <co>bar</co>
  <topic/>
  </dept>
</depts>
</data>

This XML document consists of a company table and a department table.  
The <co> element must uniquely identifies a company, the sequence 
of the <dname> element and the <co> element uniquely identifies a 
department.

First, this pattern captures the element structure.  

<?xml version="1.0"?>
<grammar
  xmlns="http://www.thaiopensource.com/trex"
  xmlns:xsd="http://www.w3.org/2000/10/XMLSchema">

<start>
  <element name="data">
    <ref name="Companies"/>
    <ref name="Depts"/>
  </element>
</start>

<define name="Companies">
  <element name="companies">
    <zeroOrMore>
      <ref name="Company"/>
    </zeroOrMore>
  </element>
</define>

<define name="Company">
  <element name="company">
    <element name="co"> 
      <anyString/>
    </element>
    <element name="stock">
      <data type="xsd:decimal"/>
    </element>
  </element>
</define>

<define name="Depts">
  <element name="depts">
    <zeroOrMore>
      <ref name="Dept"/>
    </zeroOrMore>
  </element>
</define>

<define name="Dept">
  <element name="dept">
    <element name="dname"> 
      <anyString/>
    </element>
    <element name="co">
      <anyString/>
    </element>
    <element name="topic">
      <anyString/>
    </element>
  </element>
</define>

</grammar>


Now, we are ready to specify keys and foreign keys.  We first specify
that the content of <co> of the type "Company" is a key.  We then
specify that the sequence of the conent of <co> and that of <dname> of
the type "Dept" is a key.

key Company [--- ./co/data() ---] 
key Dept [--- ./dname/data(), ./co/data() ---]

We can easily provide an XML-based syntax.  E.g.,

<key type="Company">
  <path>./co/data()</path>
</key>

<key type="Dept">
   <path>./dname/data()</path>
   <path>./co/data()</path>
<key>

We can further specify that the content of <co> 
of the type "Dept" uniquely references to an element 
of the type "Company".

foreign key Dept [--- ./co/data() ---] 
references Company [--- ./co/data() ---] 

Here is an XML syntax.

<foreignKey type="Dept">
   <from>
     <path>./co/data()</path>
   </from>
   <to>
     <path>./co/data()</path>
   </to>
</foreignKey>

More about this, see the UCM paper.

Cheers,

Makoto


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [Elist Home]


Powered by eList eXpress LLC