Luixv
Luixv

Reputation: 8710

XSD Pattern restriction. How to get a shorthand

I have an XSD grammar where one SimpleType which should be restricted to a 6 comma-separated numeric values. That is, each element is of the form:

-?\d*\.?\d+\s*

As I need a 6-tuple I can write the following pattern:

<xs:pattern value="-?\d*\.?\d+\s*,\s*-?\d*\.?\d+\s*,\s*-?\d*\.?\d+\s*,\s*-?\d*\.?\d+\s*,\s*-?\d*\.?\d+\s*,\s*-?\d*\.?\d+\s*"/>

I wanted to short it. I've tried with the following pattern:

<xs:pattern value="(-?\d*\.?\d+\s*,){5}\s*-?\d*\.?\d+\s*" />

But seems to be wrong. I cannot recognise the error. Can anybody tell me why is this wrong?

Thanks in advance

Upvotes: 0

Views: 67

Answers (1)

Michael Kay
Michael Kay

Reputation: 163342

In what way does it fail?

It works for me (with Saxon as the schema validator). With the schema

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:saxon="http://saxon.sf.net/">
  <xs:element name="top">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:pattern value="(-?\d*\.?\d+\s*,){5}\s*-?\d*\.?\d+\s*" />
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
</xs:schema>

this document is valid:

<top>1,2,3,4,5,6</top>

and this one is invalid:

<top>1,2,3,4,5</top>

Upvotes: 1

Related Questions