开发者

Use XSD to validate a CSV value?

开发者 https://www.devze.com 2023-01-12 14:49 出处:网络
I have an xml file with an a开发者_StackOverflow社区ttribute that looks something like this: <Element attribute=\"1234,2345,3413,6532\" />

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

精彩评论

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

关注公众号