Hi,
I have a primitive type int type which is restricted to the values of 0
to 23. Let me call the restricted type "HourType". I want to write out a
list of the form:
HourRangeType => HourType |
HourType '-' HourType
RangeList => HourRangeType ( ',' HourRangeType )*
Is there a way to express the RangeList type in schema?
Thanks,
Kenneth
I think the only way to impose this restriction is via a pattern facet
on xs:string. As schema doesn't allow fo variables with in it's
patterns, it can get rather messy! I defined the following sub-
expression for pattern:
HourTypeRE = (1?[0-9]|2[0-3]) # matches the integers 0-23
(hopefully)
HourRangeRE = HourTypeRE (-HourTypeRE)?
RangeListRE = HourRangeRE(,HourTypeRE)*
Expanding that out gives a pattern of:
RangeListRE = (1?[0-9]|2[0-3])(-(1?[0-9]|2[0-3]))?(,(1?[0-9]|2[0-3])(-
(1?[0-9]|2[0-3]))?)*
Giving an XML schema snippet of:
<xs:simpleType name='RangeList'>
<xs:restriction base='xs:string'>
<xs
attern value='(1?[0-9]|2[0-3])(-(1?[0-9]|2[0-3]))?(,(1?[0-9]|
2[0-3])(-(1?[0-9]|2[0-3]))?)*'/>
</xs:restriction>
</xs:simpleType>
You would need to parse the resultant string in your application to
extract all the releavnt parts. In the light of that you may want to
consider defining a schema that makes more use of XML to tokenise the
sub-components. e.g. your XML instance ends up looking like:
<RangeList>
<HourRange from='1' to='14'/>
<HourRange from='6' to='12'/>
<HourRange from='4' to='4'/>
</RangeList>
HTH,
Pete Cordell
Codalogic
Visit
http://www.codalogic.com/lmx/
for XML Schema to C++ data binding