I am trying to create an XSD that should check the integer value of an XML element. What I want to achieve is to limit this value to both ranges (so min / maxInclusive will not) and some specific values.
We give an example. I want an element to be valid if it contains 1, a number from 9 to 12, or a number from 15 to 20. I tried to create a template
<xs:pattern value="[(1)(9-12)(15-20)]"/>
but it doesn’t work, because (as I understand it) part 9-12 does something like 9 | 0 | 1 .... because she does not interpret 12 as a whole. With single digits, e.g.
<xs:pattern value="[(1)(3-5)(7-9)]"/>
it works. I tried to enclose multi-digit numbers in parentheses such as 9- (12), but to no avail.
I could try using enums for this as follows:
<xs:restriction base="xs:integer"> <xs:enumeration value="1"/> <xs:enumeration value="9"/> <xs:enumeration value="10"/> <xs:enumeration value="11"/> <xs:enumeration value="12"/> .... </xs:restriction>
but it is incredibly impractical, especially for large ranges. The same applies to the same as a template:
<xs:pattern value="1|9|10|11|12|15....."/>
So, I see two ways right now: either there is a template that I can’t come up with myself, which allows me to use several single numbers and ranges, including multi-valued numbers, or there is a way like something like
<xs:enumeration value="9"-"12"/>
It seems quite difficult to create such a regular expression in general, as far as I can tell from what my colleagues with a lot of experience with regular expressions say. Based on localized solutions for my exact example, it’s not too difficult here, but I'm looking for a universal solution with which it is easy to get an arbitrary list (1,3-5,9-12,99) -999) and make the XSD restriction from it without unnecessary hassle.
From what I see, the enumeration approach with dividing ranges into all numbers contained in it seems to be the most likely approach that can really be possible, but it will still be incredibly ugly.
This is roughly XSD 1.1. Maybe there is a completely different approach that I have not yet stumbled upon?
EDIT: Despite the fact that I just answered myself, I will leave this question open for today if someone can come up with something more elegant than ... what I created. (I'm not sure about deleting the question - if you think this is not useful, check this or something like that.)