I have a tag like this
<order>foo,bar,goo,doo,woo</order>
that I need to validate with an xsd.
How do I write a regexp pattern that matches the string that contains:
<order>foo,bar,goo,doo,woo</order>
<order>foo,bar,goo</order>
<order>foo,doo,goo,woo</order>
<order>woo,foo,goo,doo,bar</order>
<order></order>
<order>foo,foo</order>
<order>,</order>
<order>fo</order>
<order>foobar</order>
This have to work in different XML/XSD parsers.
I don't think you can express all the rules in a regular expression. Especially, it will be tough to enforce "maximum once". This is the closest I come up with,
<xs:simpleType name="order">
<xs:annotation>
<xs:documentation>
Comma-separated list of anything
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:pattern value="[^,]+(,\s*[^,]+)*"/>
</xs:restriction>
</xs:simpleType>
You might want try to use space as separator. That's more common in XML files. XML Schema has a builtin type "list
" defined for space-separated list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With