How to define multiple elements in XML Schema with the same name and different attribute value allow

Posted by David Skyba on Stack Overflow See other posts from Stack Overflow or by David Skyba
Published on 2008-10-07T10:57:03Z Indexed on 2010/05/06 3:18 UTC
Read the original article Hit count: 287

Filed under:

I would like to create XML Schema for this chunk of xml, I would like to restrict the values of "name" attribute, so that in output document on and only one instance of day is allowed for each week day:

<a>
  <day name="monday" />
  <day name="tuesday" />
  <day name="wednesday" />
</a>

I have tried to use this:

 <xs:complexType name="a">
  <xs:sequence>
    <xs:element name="day" minOccurs="1" maxOccurs="1">
      <xs:complexType>
        <xs:attribute name="name" use="required">
          <xs:simpleType>
            <xs:restriction base="xs:string">
              <xs:enumeration value="monday" />
            </xs:restriction>
          </xs:simpleType>
        </xs:attribute>
      </xs:complexType>
    </xs:element>
    <xs:element name="day" minOccurs="1" maxOccurs="1">
      <xs:complexType>
        <xs:attribute name="name" use="required">
          <xs:simpleType>
            <xs:restriction base="xs:string">
              <xs:enumeration value="tuesday" />
            </xs:restriction>
          </xs:simpleType>
        </xs:attribute>
      </xs:complexType>
    </xs:element>
  </xs:sequence>
</xs:complexType>

but XML Schema validator in eclipse says error "Multiple elements with name 'day', with different types, appear in the model group.".

Is there any other way?

© Stack Overflow or respective owner

Related posts about xml-schema