首页 > 解决方案 > XML 模式的正则表达式

问题描述

我有这个 xml 内容,id 值从 1 到 193。

<member lang="en" id="UN193">
    <name>Zimbabwe</name>
    <admissionYear>1980</admissionYear>
    <population year="2019">14645468</population>
    <continent>Africa</continent>
    <officialLangInfo>
        <language script="Latin" family="Indo-European">English</language>
        <language script="Latin" family="Niger–Congo">Chewa</language>
        <language script="Latin" family="Niger–Congo">Kalanga</language>
        <otherLanguage>Chibarwe</otherLanguage>
    </officialLangInfo>
</member>

我创建了这个限制,这给了我一个错误验证文件。有什么建议么?非常感谢。

    <xs:attribute name="id" use="required">
            <xs:simpleType>
                <xs:restriction base="xs:ID">
                    <xs:pattern value="[UN][0-9]{1,3}"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>

标签: regexxmlschema

解决方案


一种可能性是使用to 允许范围内的UN\[0-9]{1,3}id 。UN0UN999

如果你想更精确并且只允许从 1 到 193 的 id,你可以尝试类似UN(1[0-9][0-3]|[1-9][0-9]|[1-9]).

这里的例子。


推荐阅读