使用XSD验证CSV值?
问题描述:
我有一个属性的XML文件看起来是这样的:使用XSD验证CSV值?
<Element attribute="1234,2345,3413,6532" />
我需要一种方法来验证该属性值是整数的一定范围内的逗号分隔的列表。任何人都知道如何使用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位整数。
谢谢,这让我有一部分。如果范围是0-183784那么该怎么办?使用正则表达式验证会变得棘手。有没有其他方法可以做到这一点?我已经有了一个简单的类型来验证一个整数是否在正确的范围内,有什么方法可以将它与你的例子结合起来吗? – user113164 2010-08-24 13:37:01