开发者

Use XSD to validate a CSV value?

I have an xml file with an a开发者_StackOverflow社区ttribute that looks something like this:

<Element attribute="1234,2345,3413,6532" />

I need a way to validate that the attribute value is a comma separated list of integers within a certain range. Anyone know how to do this using XSD?

Thanks!


This should restrict the attribute's values to a comma-separated list of integers:

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

If the range you mention is simple enough you might be able to express that in the RE, for example [1-9]\d{3} for a 4-digit integer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜