logeeks
logeeks

Reputation: 4979

specifying values in enum in XSD

I have defined a enum as below in the XSD file

 <xs:simpleType name="PaperSizes">
    <xs:restriction base="xs:string">
      <xs:enumeration value="NUMBERS"></xs:enumeration>
      <xs:enumeration value="PICTURE"></xs:enumeration>
      <xs:enumeration value="RTF"></xs:enumeration>
    </xs:restriction>

I need to override the detault values assigned by the compiler. ie:- for NUMBERS the default value will be 0. I need the value 2 for it.

What changes i need to make?

Thanks.

Upvotes: 4

Views: 4481

Answers (1)

tom redfern
tom redfern

Reputation: 31780

You cannot set a different default for each of the values in a collection. You can set one default value for any xsd simple type with the "default" keyword.

So if you want to set a default value in your example above you could do something like:

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="root">
    <xs:complexType>
      <xs:sequence>
        <xs:element default="PICTURE" name="PaperSizes">
          <xs:simpleType>
            <xs:restriction base="xs:string">
              <xs:enumeration value="NUMBERS" />
              <xs:enumeration value="PICTURE" />
              <xs:enumeration value="RTF" />
            </xs:restriction>
          </xs:simpleType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

I hope this helps.

Upvotes: 5

Related Questions