XML Schema Case Insensitive Enumeration of Simple Type String

安稳与你 提交于 2019-12-03 10:20:30

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.

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!