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

XML Schema - inheritance, attribute redeclaration

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

Apr 23 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
"Krzysztof Nogal" <kn****@gmail.comwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
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

Apr 27 '07 #2

P: n/a
Hi Stan,

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

Regards,
Krzysztof Nogal

Apr 30 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.