[XSD] derivation by restriction

L

Lars Geldner

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
 
S

Stan Kitsis [MSFT]

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
 
L

Lars Geldner

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?
 
H

Henry S. Thompson

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: (e-mail address removed)
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top