1
votes

I'm not able figure out how to express the following with Xsd: an elment with a simpleType restriction (enumeration of values) and require an attribute on this element. For example:

<myElement some_id_value="1">Apples</myElement>

Where the simple type is defined as:

<xs:simpleType name="simpleType_Fruit">
  <xs:restriction base="xs:string">
    <xs:enumeration value="Apples" />
    <xs:enumeration value="Bananas" />
    <xs:enumeration value="Oranges" />
  </xs:restriction>  
</xs:simplType>

My element right now is defined as:

<xs:element name="myElement" type="simpleType_Fruit"/>

A similar question asked here, and may be answered, but I'm not sure (there is only a single plus vote on the answer)

XSD: How to derive a simpletype both to add a attribute to it and to restrict the acceptable value of it

1

1 Answers

1
votes

You can use your "simpleType_Fruit" as a base type right at the element declaration and extend one with required attributes.

<xs:element name="myElement">
    <xs:complexType>
        <xs:simpleContent>
            <xs:extension base="simpleType_Fruit">
                <xs:attribute name="some_id_value" type ="xs:byte"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
</xs:element>
<xs:simpleType name="simpleType_Fruit">
    <xs:restriction base="xs:string">
        <xs:enumeration value="Apples"/>
        <xs:enumeration value="Bananas"/>
        <xs:enumeration value="Oranges"/>
    </xs:restriction>
</xs:simpleType>