- From: <Tomas.Oberg@partnertech.se>
- Date: Wed, 9 Jul 2003 11:38:47 +0200
- To: jeni@jenitennison.com, Tomas.Oberg@partnertech.se
- Cc: xmlschema-dev@w3.org
- Message-ID: <D2DCE0BA75D7D4118FB500508BEED2E8037598D5@puff.partnertech.se>
Hi! OK, an example: I have the following database schema (SQL Server 2000) CREATE TABLE [dbo].[Contents] ( [ContentID] [int] IDENTITY (1, 1) NOT NULL , [Content] [varchar] (256) NOT NULL , [ColumnNameID] [int] NOT NULL ) ON [PRIMARY] GO CREATE TABLE [dbo].[ColumnNames] ( [ColumnNameID] [int] IDENTITY (1, 1) NOT NULL , [ColumnName] [varchar] (64) NOT NULL ) ON [PRIMARY] GO And this is part of the xsd mapping schema... <xsd:element name="Content1" maxOccurs="1" sql:relation="[Contents]" sql:key-fields="ContentID" sql:relationship="TestObjects_TOC TOC_Contents"> <xsd:complexType> <xsd:attribute name="ContentID" type="xsd:integer" use="required" sql:field="ContentID" sql:datatype="int" sql:hide="true"/> <xsd:attribute name="Content" type="xsd:integer" use="required" sql:field="Content" sql:datatype="varchar(256)"/> <xsd:attribute name="ColumnNameID" type="xsd:integer" use="required" sql:field="ColumnNameID" sql:datatype="int" sql:hide="true"/> <xsd:attribute name="ColumnName" use="required" type="xsd:string" fixed="ColumnName1" sql:relation="[ColumnNames]" sql:key-fields="ColumnNameID" sql:field="ColumnName" sql:relationship="Contents_ColumnNames" sql:datatype="varchar(64)"/> </xsd:complexType> </xsd:element> <xsd:element name="Content2" maxOccurs="1" sql:relation="[Contents]" sql:key-fields="ContentID" sql:relationship="TestObjects_TOC TOC_Contents"> <xsd:complexType> <xsd:attribute name="ContentID" type="xsd:integer" use="required" sql:field="ContentID" sql:datatype="int" sql:hide="true"/> <xsd:attribute name="Content" type="xsd:string" use="required" sql:field="Content" sql:datatype="varchar(256)"/> <xsd:attribute name="ColumnNameID" type="xsd:integer" use="required" sql:field="ColumnNameID" sql:datatype="int" sql:hide="true"/> <xsd:attribute name="ColumnName" use="required" fixed="ColumnName2" sql:relation="[ColumnNames]" sql:key-fields="ColumnNameID" sql:field="ColumnName" sql:relationship="Contents_ColumnNames" sql:datatype="varchar(64)"/> </xsd:complexType> </xsd:element> 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. Thanks for any advice or workaround. Tomas Öberg -----Ursprungligt meddelande----- Från: Jeni Tennison [mailto:jeni@jenitennison.com] Skickat: den 9 juli 2003 11:07 Till: Tomas.Oberg@partnertech.se Kopia: xmlschema-dev@w3.org Ämne: Re: fixed attribute in a xsd mapping schema? Hi Tomas, > Hi! I would like to have a fixed attribute in an element of my xsd > schema which maps to a SQL Server 2000 database. Is that possible? You can have a fixed attribute (an attribute with a fixed value) easily enough, using the 'fixed' attribute on the attribute declaration. For example: <xs:attribute name="foo" fixed="bar" /> means that if the foo attribute appears in the document then it must have the value 'bar'. > What I'm trying to solve is: to have different datatypes depending > on what the contents of an element is. Is there a workaround? I'm not sure exactly what you mean by having different datatypes depending on the content of an element, but it sounds as though it might be a co-occurrence constraint of some kind, in which case you might be out of luck. If you provide some examples of what you're trying to achieve (some valid and invalid elements) then we might be able to help, or at least tell you whether it can or can't be done. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/
Received on Wednesday, 9 July 2003 05:39:01 UTC