Subject: Using constrainst on multiple schemas
Posted By: Chamkaur Post Date: 12/14/2006 11:47:27 PM
Hi there,

It is possible to define contraints in a schema that is being referenced. Assuming I have 2 separate schemas namely schemaA and schemaB.

In schemaA, I have an INCLUDE statement to reference to schemaB.  And I would like to define the constraints in schemaB to ensure that the unique id is indeed unique.  

I understand I can achieve this by defining the constraint in schemaA but I would really like to keep the contraint definition within the respective schema as I may have a few schemas being referenced by schemaA which might get messy.  Thanks

SchemaA

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.domain.com.au" targetNamespace="http://www.domain.com.au" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:include schemaLocation="TableSchemas/tscm_location.xsd"/>
    <xs:element name="TDM">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="tscm_location" type="tscm_location" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

SchemaB

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.domain.com.au" elementFormDefault="qualified">
    <xs:complexType name="tscm_location">
        <xs:sequence>
            <xs:element name="locn_id" type="xs:int"/>
            <xs:element name="locn_name" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
    <!--<xs:unique name="Constraint1">
    <xs:selector xpath=".//tscm_location"/>
    <xs:field xpath="locn_id"/>
</xs:unique>-->
</xs:schema>

Reply By: mhkay Reply Date: 12/15/2006 6:08:07 AM
It's a good idea to get the distinction clear between a "schema" and a "schema document". The situation you are describing does not have several schemas, it has a single schema assembled from multiple schema documents.

Identity constraints such as xs:unique are associated with element declarations, and although they are globally named, they have to be written inline within the element declaration. So as far as I'm aware, there's no way of doing what you want - except of course by using non-XSD mechanisms to assemble your schema documents, for example XInclude or plain old external entities.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference

Go to topic 53648

Return to index page 92
Return to index page 91
Return to index page 90
Return to index page 89
Return to index page 88
Return to index page 87
Return to index page 86
Return to index page 85
Return to index page 84
Return to index page 83