By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,402 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,402 IT Pros & Developers. It's quick & easy.

[XSD] derivation by restriction

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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!
Jul 20 '05 #2

P: n/a
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" <ge*****@web.de> wrote in message
news:33*************@news.dfncis.de...
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

Jul 20 '05 #3

P: n/a
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?

Jul 20 '05 #4

P: n/a
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: ht@inf.ed.ac.uk
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.