【发布时间】:2010-08-23 21:26:36
【问题描述】:
我有一个 xml 文件,其属性如下所示:
<Element attribute="1234,2345,3413,6532" />
我需要一种方法来验证属性值是一个逗号分隔的特定范围内的整数列表。有谁知道如何使用 XSD 做到这一点?
谢谢!
【问题讨论】:
标签: validation csv xsd
我有一个 xml 文件,其属性如下所示:
<Element attribute="1234,2345,3413,6532" />
我需要一种方法来验证属性值是一个逗号分隔的特定范围内的整数列表。有谁知道如何使用 XSD 做到这一点?
谢谢!
【问题讨论】:
标签: validation csv xsd
这应该将属性的值限制为以逗号分隔的整数列表:
<xsd:element name="Element">
<xsd:complexType>
<xsd:attribute name="attribute">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="\d+(,\d+)*" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
如果您提到的范围足够简单,您也许可以在 RE 中表达它,例如 [1-9]\d{3} 表示 4 位整数。
【讨论】: