Rather than one <rate>
element with an xs:integer
content, and another one without any content, you can only declare one <rate>
element that accepts any integer value or nothing as its contents.
Practically, this can be done with the <xs:union>
element:
<xs:simpleType name="emptyString">
<xs:restriction base="xs:string">
<xs:maxLength value="0"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="rate">
<xs:simpleType>
<xs:union memberTypes="xs:integer emptyString"/>
</xs:simpleType>
</xs:element>
This will accept <rate/>
, <rate></rate>
, <rate>42</rate>
(or any other xs:integer
value), but not <rate>Hello, World!</rate>
.
Note that for this to work, you must have set your prefix-less namespace in the schema to the same as your target namespace, or otherwise, emptyString
in the memberTypes
attribute will not be found. (Of course, you can instead also define a prefix for your target namespace and use that.)
I have omitted any explanations on how to write the complete schema and how to use maxOccurs
etc. because from your question I figure you already know how to do that. Please let me know if you need any further information on this.