I have the following XSD which was generated by VS from an example XML file:
You can combine the two types you wish to allow via xs:union
:
<xs:element name="amperage_rating" type="empty_or_decimal"/>
<xs:simpleType name="empty_or_decimal">
<xs:union memberTypes="empty xs:decimal"/>
</xs:simpleType>
<xs:simpleType name="empty">
<xs:restriction base="xs:string">
<xs:enumeration value=""/>
</xs:restriction>
</xs:simpleType>
It sounds as if your use case is very like some of the motivating cases for xsi:nil. From your description, it sounds as if you made the element nillable, but then fed it an non-nilled instance of the form
<amperage_rating unit="A"></amperage_rating>
instead of specifying that the element should be nilled:
<amperage_rating unit="A" xsi:nil="true"></amperage_rating>
If you want to modify the type, the methods described by kjhughes and Michael Kay should work fine.
There are two approaches. One is what @kjhughes suggests: define a union between xs:decimal
and a zero-length-string type. The other, which I personally prefer, is to define a list type with item type xs:decimal
and maxLength 1. Although the effect on validation is exactly the same, I think the list type is easier to use when the schema is used for data typing: certainly with XSLT and XQuery, where atomizing the element will give you a sequence of zero or one decimals.