- From: Jeni Tennison <jeni@jenitennison.com>
- Date: Wed, 9 Jul 2003 11:04:51 +0100
- To: Tomas.Oberg@partnertech.se
- CC: xmlschema-dev@w3.org
Hi Tomas,
> I use the two tables Contents and ColumnNames to store data in SQL
> Server 2000. Every Contents instance points to a ColumnNames
> instance. But I don't have any control of what datatype I store in
> the Contents table. That's why I would like to be able to use
> different datatypes of the Content element according to which
> ColumnName the Content points to.
In XML terms, then, you want to have:
<Content ContentID="1" Content="1" ColumnNameID="1"
ColumnName="ColumnName1" />
<Content ContentID="2" Content="foo" ColumnNameID="2"
ColumnName="ColumnName2" />
and you want to say that the Content attribute of the first <Content>
element is of type xs:int and the Content attribute of the second
<Content> element is of type xs:string.
The only way you can arrange this co-occurrence constraint using XML
Schema is to add an xsi:type attribute that controls the type of the
Content attribute. Your instance would look like:
<Content ContentID="1" Content="1" ColumnNameID="1"
ColumnName="ColumnName1" xsi:type="ColumnName1" />
<Content ContentID="2" Content="foo" ColumnNameID="2"
ColumnName="ColumnName2" xsi:type="ColumnName2" />
Alternatively, you can create a transformation that takes your
document and converts it into:
<ColumnName1 ContentID="1" Content="1" ColumnNameID="1" />
<ColumnName2 ContentID="2" Content="foo" ColumnNameID="2" />
An XML Schema schema can declare the elements <ColumnName1> and
<ColumnName2> with different types.
Or you could switch to using RELAX NG instead, in which the
co-occurrence constraint can be expressed very easily:
<element name="Content">
<attribute name="ContentID"><data type="int" /></attribute>
<attribute name="ColumnNameID"><data type="int" /></attribute>
<choice>
<group>
<attribute name="ColumnName">
<value>ColumnName1</value>
</attribute>
<attribute name="Content"><data type="int" /></attribute>
</group>
<group>
<attribute name="ColumnName">
<value>ColumnName2</value>
</attribute>
<attribute name="Content"><data type="string" /></attribute>
</group>
...
</choice>
</element>
Let us know which alternative you want to investigate if you need
further help with it.
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
Received on Wednesday, 9 July 2003 06:04:58 UTC