XML模式案例简单类型字符串的不敏感枚举

时间:2022-11-16 16:06:12

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.

我需要在XML模式(.xsd)文件中使用不区分大小写的字符串枚举类型。通过执行以下操作,我可以获得不区分大小写。

<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.

唯一的问题是我没有得到枚举值。使用Visual Studio编写XML时,我不会得到漂亮的intellesense。以下将给出我的枚举,但它区分大小写。

<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.

我希望枚举“on”,“off”并允许输入不区分大小写的版本。

3 个解决方案

#1


10  

IBM developerWorks has an article on how to use XSLT to perform the construction of the full set of enumeration alternatives in an automated fashion. It is presented as a workaround to the lack of case-insensitive enumerations.

IBM developerWorks上有一篇文章介绍了如何使用XSLT以自动方式构建完整的枚举备选方案。它是作为缺少不区分大小写的枚举的变通方法而提出的。

#2


15  

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

如果您希望保持不区分大小写的验证,同时仍在Visual Studio 2010中获取Intellisense,则可以使用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.

这是有效的,因为它利用了Visual Studio 2010在构建Intellisense数据时仅处理union中第一个简单类型的事实。但是,当它验证文档时,它会处理两者,这意味着“On”仍然被确定为有效,即使它不在枚举值列表中。

#3


0  

Well, you could just list all the permutations as patterns :)

好吧,你可以把所有的排列列为模式:)

#1


10  

IBM developerWorks has an article on how to use XSLT to perform the construction of the full set of enumeration alternatives in an automated fashion. It is presented as a workaround to the lack of case-insensitive enumerations.

IBM developerWorks上有一篇文章介绍了如何使用XSLT以自动方式构建完整的枚举备选方案。它是作为缺少不区分大小写的枚举的变通方法而提出的。

#2


15  

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

如果您希望保持不区分大小写的验证,同时仍在Visual Studio 2010中获取Intellisense,则可以使用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.

这是有效的,因为它利用了Visual Studio 2010在构建Intellisense数据时仅处理union中第一个简单类型的事实。但是,当它验证文档时,它会处理两者,这意味着“On”仍然被确定为有效,即使它不在枚举值列表中。

#3


0  

Well, you could just list all the permutations as patterns :)

好吧,你可以把所有的排列列为模式:)