Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Schema Case Insensitive Enumeration of Simple Type String

I am in need of a case insensitive string enumeration type in my XML schema (.xsd) file. I can get case insensitive by doing the following.

<xs:simpleType name="setDigitalPointType">
    <xs:restriction base="xs:string">
        <xs:pattern value="[Oo][Nn]" />
        <xs:pattern value="[Oo][Ff][Ff]" />
    </xs:restriction>
</xs:simpleType>

The only problem is that I get no enumeration values. I will not get the nice intellesense when using Visual Studio to write my XML. The following will give me enumerations but it is case sensitive.

<xs:simpleType name="setDigitalPointType">
    <xs:restriction base="xs:string">
        <xs:enumeration value="on" />
        <xs:enumeration value="off" />
    </xs:restriction>
</xs:simpleType>

This will give me my enumerations but if I ever receive a value of "On", "ON", or "oN" it will fail verification.

I want enumeration of "on", "off" and allow entry of case insensitive versions.

like image 610
Bobby Cannon Avatar asked Dec 11 '08 13:12

Bobby Cannon


People also ask

Is XML schema case sensitive?

Or XML is widely accepted as case-sensitive? Yes, it is.

Are XML cases insensitive?

XML tags are case sensitive. All XML elements must be properly nested. All XML documents must have a root element.

What is enumeration in XML?

Enumerations are a base simple type in the XSD specification containing a list of possible values. Single-valued enumerations are shown as restrictions of the base simple type xs:token , as illustrated below: ? < xs:simpleType name=”GraduationPlanTypeMapType”>

Is DTD case sensitive?

Values defined explicitly by the DTD are case-insensitive.


1 Answers

If you want to both keep the case-insensitive validation, while still getting Intellisense in Visual Studio 2010, you can use a union:

<xs:simpleType name="setDigitalPointType">
    <xs:union>
        <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:enumeration value="on" />
                <xs:enumeration value="off" />
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:pattern value="[Oo][Nn]" />
                <xs:pattern value="[Oo][Ff][Ff]" />
            </xs:restriction>
        </xs:simpleType>
    </xs:union>
</xs:simpleType>

This works because it exploits the fact that Visual Studio 2010 only processes the first simple type in a union when it builds it's Intellisense data. However when it validates a document, it processes both, which means "On" is still determined to be valid even though it isn't in the list of enumeration values.

like image 183
Orvid King Avatar answered Sep 19 '22 20:09

Orvid King