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

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   RE: [xml-dev] key constraint question

[ Lists Home | Date Index | Thread Index ]

> From: Rick Jelliffe [mailto:ricko@allette.com.au]

> Actually, I think you can represent your constraint in XML 
> Schemas (someone
> will be along very shortly to correct me if I have this wrong :-) :
>  * make a complex type for your table B reference
>  * make two derived types from that complex type, one with the 
>   relationship attribute restricted to "needed", and one with 
> the attribute
>   restricted to "needed"
>  * in the schema, declare that the first TableB in TableA uses the
>   type restrictied to "needed" and that the other use the 
> type restricted
>   to "optional".  (In XML Schemas,  subelements with the same name
>   can have different types, as long as there is no ambiguity 
> about which
>   type would be selected: so  (TableB, TableB*) the two particles
>   can have different types.)

You mean like this?:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
elementFormDefault="qualified" attributeFormDefault="unqualified">
  <xs:element name="TableA">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="primaryKey"/>
        <xs:element name="TableB" type="TableB_Type1" minOccurs="1"/>
        <xs:element name="TableB" type="TableB_Type2" minOccurs="0"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

    <xs:attribute name="relationship">
                <xs:simpleType>
                  <xs:restriction base="xs:token">
                    <xs:pattern value="needed|optional"/>
                  </xs:restriction>
                </xs:simpleType>
    </xs:attribute>

  <xs:complexType name="TableB_Type">
     <xs:sequence>
      <xs:element name="primaryKey" type="xs:string"/>
    </xs:sequence>
      <xs:attribute ref="relationship"/>
  </xs:complexType>

  <xs:complexType name="TableB_Type1">
     <xs:complexContent>
     <xs:restriction base="TableB_Type">
       <xs:sequence>
        <xs:element name="primaryKey" type="xs:string"/>
      </xs:sequence>
      <xs:attribute ref="relationship" fixed="needed"/>
    </xs:restriction>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="TableB_Type2">
     <xs:complexContent>
     <xs:restriction base="TableB_Type">
       <xs:sequence>
        <xs:element name="primaryKey" type="xs:string"/>
      </xs:sequence>
      <xs:attribute ref="relationship" fixed="optional"/>
    </xs:restriction>
    </xs:complexContent>
  </xs:complexType>
</xs:schema>

I couldn't get this past either XSV or SQC, although I probably don't have
the very latest versions.   I thought redeclarations of same-named types was
disallowed, although maybe the errata clarified this a bit?  Or maybe I just
wrote the schema wrong...  (Or maybe I need newer validators...)







 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS