XML Schema - inheritance, attribute redeclaration

Krzysztof Nogal

Usenet Archive
Joined
Oct 3, 2005
Messages
12
Reaction score
0
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
 

Stan Kitsis MSFT

Usenet Archive
Joined
Dec 15, 2004
Messages
64
Reaction score
0
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.
 

Krzysztof Nogal

Usenet Archive
Joined
Oct 3, 2005
Messages
12
Reaction score
0
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

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,246
Members
248,133
Latest member
DujonT

Latest Threads

Top