Reputation: 31
I'm trying to understand the use of patterns in XSD. Hows does '+' in a pattern for a restriction work in XSD?
After some research, I found out that I can use restrictions with patterns. I do understand that the "+" means 1 or more. But will it also apply in this case?
<xsd:simpleType name="typeNumber">
<xsd:restriction base="xsd:ID">
<xsd:pattern value="nr[0-9]+"/>
</xsd:restriction>
</xsd:simpleType>
Will, for example, the value nr12345
be valid?
Furthermore, I would like to know how it would be possible to make the acceptable value between nr01
and nr10
.
Upvotes: 3
Views: 586
Reputation: 626794
You may use
<xsd:simpleType name="typeNumber">
<xsd:restriction base="xsd:ID">
<xsd:pattern value="nr(0?[1-9]|10)"/>
</xsd:restriction>
</xsd:simpleType>
Details
The regex will match an entire string that matches
nr
- nr
at the start of the string(0?[1-9]|10)
- an optional 0
followed with a non-zero digit (see 0?[1-9]
alternative) or (|
) 10
value.Upvotes: 0
Reputation: 111541
This XSD type,
<xsd:simpleType name="typeNumber">
<xsd:restriction base="xsd:ID">
<xsd:pattern value="nr0[1-9]"/>
<xsd:pattern value="nr10"/>
</xsd:restriction>
</xsd:simpleType>
will allow nr01
through nr09
and nr10
, as requested, without needing +
, which, yes, does mean 1 or more occurences.
Upvotes: 2