[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: key constraint question


xs attribute versus xs element
> From: Rick Jelliffe [mailto:ricko@a...]

> 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...)




PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.