views:

211

answers:

2

I have an XML attribute representing the version numbering of a file.

The file version is identified internally by two byte fields so that, theoretically the versión could go from: 0.1 to 255.255.

Is there any way to express that as a pattern restriction or any other kind of restriction in an XML Schema?

Note: The problem is not restricting the format to three numbers, a dot and another three numbers. The problem is disallowing values greater than 255...

A: 

It was a lot easier than I thought. I was focusing on a pattern restriction when a max-min value is a lot easier.

<xs:restriction base="xs:double">
  <xs:maxInclusive value="255.255" />
  <xs:minInclusive value="0.1" />
</xs:restriction>

That allows values from 0.1 to 255.255 included.

Jorge Córdoba
I don't know that that'll do exactly what you want? Won't it allow, for example, 0.256 as it's less than 255.255?
Chris R
Ohhhhhhhhhhhhhhhhhhhh shiiiiiit ... you're absolutely right!!
Jorge Córdoba
+1  A: 

I think this should do the trick (not had a chance to check I'm afraid)...

<xs:simpleType name="version">
    <xs:restriction base="xs:string">
     <xs:pattern value="([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])[.]([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])"/>
    </xs:restriction>
</xs:simpleType>
Chris R
That did it!! Thanks!
Jorge Córdoba