[XSD] derivation by restriction

Discussion in 'XML' started by Lars Geldner, Dec 27, 2004.

  1. Lars Geldner

    Lars Geldner Guest

    Hello,

    I'm searching for a possibility to define a complex type using xml
    schema that can only be derived by restriction. The sub-complex type
    should have a content model that only contains elements which have types
    that are subsets of the element types in the super-complex type.
    For example:

    <xs:element name="A" type="A_Type" abstract="true"/>
    <xs:element name="B" type="B_Type" abstract="true"/>
    <xs:complexType name="A_Type">
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
    <xs:element ref="A" minOccurs="0" maxOccurs="unbounded"/>
    <xs:element ref="B" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="B_Type"/>

    Elements A and B can appear in any order.

    Now I want to derive "A_Type" to such an extent that the sub-type
    defines only elements that are members of the same substitutionGroup
    like A and B and appear in a special order:

    <xs:complexType name="a_A_Type">
    <xs:complexContent>
    <xs:extension base="A_Type">
    <xs:sequence>
    <xs:element ref="a_B" minOccurs="1" maxOccurs="unbounded"/>
    <xs:element ref="a_A" minOccurs="1" maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:extension>
    </xs:complexContent>
    </xs:complexType>
    <xs:element name="a_B" type="B_Type" substitutionGroup="B"/>
    <xs:element name="a_A" type="A_Type" substitutionGroup="A"/>

    My parser says:
    Ambiguous content model in the effective content model of complexType
    A_Type: the following particles overlap:
    <xs:element maxOccurs="unbounded" minOccurs="0" ref="A"/>,
    <xs:element maxOccurs="unbounded" minOccurs="0" ref="a_A"/>
    because the two particles are members of the same substitution Group.

    I'm searching for a construct that has the same task like a interface in
    Java.

    TIA,

    Lars Geldner
     
    Lars Geldner, Dec 27, 2004
    #1
    1. Advertising

  2. Lars Geldner

    Lars Geldner Guest

    Lars Geldner wrote on 27.12.2004 17:58:
    [...]
    > <xs:extension base="A_Type">

    [...]

    my fault: xs:extension is wrong, I want to use xs:restriction!
     
    Lars Geldner, Dec 27, 2004
    #2
    1. Advertising

  3. Hi Lars,

    You can restrict the usage of the derivations using "block" attribute.
    Below is an example of using "block" attribute with a base type to control
    type substitution in the instance document (it allows types derived by
    restriction and prohibits types derived by extension).

    <xs:complexType name="base" block="extension" abstract="true">
    <xs:sequence>
    <xs:element name="foo" type="xs:integer" maxOccurs="unbounded" />
    </xs:sequence>
    </xs:complexType>

    <xs:complexType name="child-x">
    <xs:complexContent>
    <xs:extension base="base">
    <xs:sequence>
    <xs:element name="bar" type="xs:string" />
    </xs:sequence>
    </xs:extension>
    </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="child-r">
    <xs:complexContent>
    <xs:restriction base="base">
    <xs:sequence>
    <xs:element name="foo" type="xs:integer" maxOccurs="1" />
    </xs:sequence>
    </xs:restriction>
    </xs:complexContent>
    </xs:complexType>

    <xs:element name="top" type="base" />

    As you can see above, I've defined a base class "base" and derived two
    children from it - one by extension (child-x) and one by restriction
    (child-r). The definition of the "top" element specifies it as of type
    "base". Type "base", in turn, blocks derivation by extension. So in my
    instance document I can use "child-r" (the following is valid):
    <top xsi:type="child-r">
    <foo>23</foo>
    </top>

    but not "child-x" (the following is invalid):
    <top xsi:type="child-x">
    <foo>23</foo>
    <bar>asdf</bar>
    </top>

    --
    Stan Kitsis
    Program Manager, XML Technologies
    Microsoft Corporation

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at
    http://www.microsoft.com/info/cpyright.htm


    "Lars Geldner" <> wrote in message
    news:...
    > Hello,
    >
    > I'm searching for a possibility to define a complex type using xml schema
    > that can only be derived by restriction. The sub-complex type should have
    > a content model that only contains elements which have types that are
    > subsets of the element types in the super-complex type.
    > For example:
    >
    > <xs:element name="A" type="A_Type" abstract="true"/>
    > <xs:element name="B" type="B_Type" abstract="true"/>
    > <xs:complexType name="A_Type">
    > <xs:sequence minOccurs="0" maxOccurs="unbounded">
    > <xs:element ref="A" minOccurs="0" maxOccurs="unbounded"/>
    > <xs:element ref="B" minOccurs="0" maxOccurs="unbounded"/>
    > </xs:sequence>
    > </xs:complexType>
    > <xs:complexType name="B_Type"/>
    >
    > Elements A and B can appear in any order.
    >
    > Now I want to derive "A_Type" to such an extent that the sub-type defines
    > only elements that are members of the same substitutionGroup like A and B
    > and appear in a special order:
    >
    > <xs:complexType name="a_A_Type">
    > <xs:complexContent>
    > <xs:extension base="A_Type">
    > <xs:sequence>
    > <xs:element ref="a_B" minOccurs="1" maxOccurs="unbounded"/>
    > <xs:element ref="a_A" minOccurs="1" maxOccurs="unbounded"/>
    > </xs:sequence>
    > </xs:extension>
    > </xs:complexContent>
    > </xs:complexType>
    > <xs:element name="a_B" type="B_Type" substitutionGroup="B"/>
    > <xs:element name="a_A" type="A_Type" substitutionGroup="A"/>
    >
    > My parser says:
    > Ambiguous content model in the effective content model of complexType
    > A_Type: the following particles overlap:
    > <xs:element maxOccurs="unbounded" minOccurs="0" ref="A"/>,
    > <xs:element maxOccurs="unbounded" minOccurs="0" ref="a_A"/>
    > because the two particles are members of the same substitution Group.
    >
    > I'm searching for a construct that has the same task like a interface in
    > Java.
    >
    > TIA,
    >
    > Lars Geldner
     
    Stan Kitsis [MSFT], Dec 27, 2004
    #3
  4. Lars Geldner

    Lars Geldner Guest

    Stan Kitsis [MSFT] wrote on 28.12.2004 00:27:
    [...]
    > You can restrict the usage of the derivations using "block" attribute.

    [...]

    Hi Stan,

    the usage of the block-attribute is clear to me.
    But what is the reason that the definded content model is ambigous? How
    can I restrict a complex type if the element types of the sub-type are a
    derivation (and in the same substitution group) like the element types
    of the super-complex type?
     
    Lars Geldner, Dec 28, 2004
    #4
  5. Once you replace 'extension' with 'restriction', your schema is fine.
    What parser is complaining about it?

    ht
    --
    Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
    Half-time member of W3C Team
    2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
    Fax: (44) 131 650-4587, e-mail:
    URL: http://www.ltg.ed.ac.uk/~ht/
    [mail really from me _always_ has this .sig -- mail without it is forged spam]
     
    Henry S. Thompson, Jan 7, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Benjamin Michotte

    derivation, restriction, extension, ...

    Benjamin Michotte, Sep 5, 2003, in forum: XML
    Replies:
    1
    Views:
    498
    Bob Foster
    Sep 5, 2003
  2. Grisha Golberg
    Replies:
    0
    Views:
    366
    Grisha Golberg
    Mar 3, 2004
  3. Cat
    Replies:
    3
    Views:
    2,674
    Henry S. Thompson
    Jun 25, 2004
  4. Dietmar Gräbner
    Replies:
    1
    Views:
    385
    Priscilla Walmsley
    Jul 19, 2004
  5. Steven T. Hatton
    Replies:
    12
    Views:
    1,700
    Jonathan Turkanis
    Aug 20, 2004
Loading...

Share This Page