Simple Schema Element/Attribute/Restriction problem

Discussion in 'XML' started by Andy Howden, Oct 20, 2003.

  1. Andy Howden

    Andy Howden Guest

    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:element name="periodData" maxOccurs="50">
    <xs:element name="periodValue" type="xs:decimal"/>
    <xs:attribute name="periodID" use="required">
    <xs:restriction base="xs:integer">
    <xs:minInclusive value="1"/>
    <xs:maxInclusive value="50"/>

    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 Howden, Oct 20, 2003
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.