I am trying to define a schema rule in XSD for which a string is 8 characters long:
<PostedDate>42183296</PostedDate>
and space filling is also allowed:
<PostedDate> </PostedDate>
which led me to XSD:
<xs:simpleType name="DateFormat"> <xs:restriction base="xs:string"> <xs:length value="8" /> //exactly 8 characters long </xs:simpleType>
but the value can also be empty (i.e. null characters):
<PostedDate></PostedDate> <PostedDate />
which made me naively try:
<xs:simpleType name="DateFormat"> <xs:restriction base="xs:string"> <xs:length value="8" /> //exactly 8 characters long <xs:length value="0" /> //exactly 0 characters long </xs:simpleType>
Which, of course, is not allowed.
As is often the case in XSD, most formats cannot be easily represented by XSD, so I decided to try the regex rule:
.{8} | ""
which is trying to convert to XSD i, type:
<xs:simpleType name="DateFormat"> <xs:restriction base="xs:string"> <xs:pattern value=".{8}|''" /> </xs:restriction> </xs:simpleType>
But this did not work:
''20101111' is not facet-valid with respect to pattern '.{8}|''' for type 'DateFormat'
I also tried
<xs:pattern value="[0-9]{8}|''" /><xs:pattern value="([0-9]{8})|('')" /><xs:pattern value="(\d{8})|('')" />
Can anyone else from the template that solves the problem corresponding - some specific template - be empty
Bonus: can anyone point out a place in the XSD documentation that says \d matches digits? Or what other special pattern codes?
regex xsd xsd-validation
Ian boyd
source share