Question

Lets assume I need to validate a pattern -- number, dash, number (i.e. 5-9).

So I've created and .xsd with something similar to this...

<xs:simpleType name="height_string_t">
  <xs:restriction base="xs:string">
    <!-- The following isn't going to work, or is it? -->
    <xs:pattern value="[0-9]-[0-9]"/>
  </xs:restriction>
</xs:simpleType>

What is the "escape character" for the pattern tag in .xsd?

Was it helpful?

Solution

To answer your question, it is the backslash. Have a look here for a concise syntax. It is really from W3C.

I would say though that you don't need to escape the dash in your case, i.e. <xs:pattern value="[0-9]-[0-9]"/> is perfectly valid and does what you describe: number, dash, number.

You could escape it, as in <xs:pattern value="[0-9]\-[0-9]"/>; again, you don't need to, the effect is the same.

If you escape it within a character class expression, then it would make a difference, i.e. a "[0\-9]" would mean one of zero, dash, nine (instead of the inclusive range zero, one, two, ... all the way to nine).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top