Simple Schema Element/Attribute/Restriction problem

A

Andy Howden

I'm trying to define a schema element (allPeriodData) containing up to 50 different decimal child elements (periodData). Each child element (periodData) identifies itself with an ID having a value from 1 to 50.
Each child element is optional (i.e. there don't have to be 50 altogether) but each ID (1-50) may occur only once within the parent element.

The best definition I have so far is this:

<xs:element name="allPeriodData">
<xs:complexType>
<xs:sequence>
<xs:element name="periodData" maxOccurs="50">
<xs:complexType>
<xs:sequence>
<xs:element name="periodValue" type="xs:decimal"/>
</xs:sequence>
<xs:attribute name="periodID" use="required">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

but, this allows the same attribute value (periodID) to be held by different periodData elements within the allPeriodData element.

I've tried to enumerate all 50 possibilities and fixing the attribute value of each, but the schema isn't valid unless each periodData element has a unique name, which I really don't want.

I feel pretty sure that this is a common thing to try to do.

Any suggestions very much appreciated.
Andy
 

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,054
Latest member
TrimKetoBoost

Latest Threads

Top