XML Schema - inheritance, attribute redeclaration

K

Krzysztof Nogal

Hi,

I have following problem with XML Schema definition.
I have following element InitialEcrHeader:

<xs:complexType name="InitialEcrHeader">
<xs:complexContent>
<xs:extension base="ecm:EcmObject">
<xs:sequence>
<xs:element name="CoordinatorContact" type="xs:token"
minOccurs="0" maxOccurs="unbounded"></xs:element>
<xs:element name="EcManager" type="xs:token" minOccurs="0"></
xs:element>
<xs:element name="DistributionList" type="xs:token"
minOccurs="0" maxOccurs="unbounded"></xs:element>
<xs:element name="LeadingChangeScope" type="xs:token"
minOccurs="0" maxOccurs="unbounded"></xs:element>
<xs:element name="ParticipantContact" type="xs:token"
minOccurs="0" maxOccurs="unbounded"></xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

There is element EcrHeader which inherits from InitialEcrHeader:
<xs:complexType name="EcrHeader">
<xs:complexContent>
<xs:extension base="ecr:InitialEcrHeader">
<xs:sequence>
<xs:element name="EcManager" type="xs:token"></xs:element>
<xs:element name="LeadingChangeScope" type="xs:token"
minOccurs="1" maxOccurs="unbounded"></xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

Goal:
In EcrHeader element there should be exatcly only one occurence of
EcManager. In InitialEcrHeader it is defined as optional. I would like
to overwrite this definition with the new one - in EcrHeader. But
while instantiating this XML Schema it is allowed to create 2
EcManager elements inside EcrHeader - and it is not allowed for my
case.
Can someone give a tip how to achive that?

<p:Header key="a2" xsi:type="p:EcrHeader">
<p:Description key="a3">
<p:Text>sd</p:Text>
</p:Description>
<p:EcManager>aa</p:EcManager>
<p:EcManager>bb</p:EcManager>
<p:LeadingChangeScope>dd</p:LeadingChangeScope>
</p:Header>

TIA
Krzysztof Nogal
 
S

Stan Kitsis [MSFT]

Hi Krzysztof,

The derivation you posted is invalid. You are trying to restrict the
original type and your example uses extension - this won't work. Here's
what you need:

<xs:complexType name="EcrHeader">

<xs:complexContent>

<xs:restriction base="ecr:InitialEcrHeader">

<xs:sequence>

<xs:element name="EcManager" type="xs:token"/>

<xs:element name="LeadingChangeScope" type="xs:token"
minOccurs="1" maxOccurs="unbounded"/>

</xs:sequence>

</xs:restriction>

</xs:complexContent>

</xs:complexType>


Note, if you want to keep other elements in this type, you'll need to list
them in the sequence.

--
Stan Kitsis
Program Manager
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
 
K

Krzysztof Nogal

Hi Stan,

Thanks for the tip - it is exactly what I missed here. It solved my
problem. Thanks!

Regards,
Krzysztof Nogal
 

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,962
Messages
2,570,134
Members
46,690
Latest member
MacGyver

Latest Threads

Top