xmlvalidationxsd

XSD validation for ANSI X3.9


I am trying to create an XSD file for validation of the Decimal String (DS) as defined in DICOM by:

This is basically an xsd:double with a limitation of 16 bytes, and the special values -Inf, +Inf and NaN are not acceptable.

So far, I tried:

<xsd:simpleType name="DecimalString">
 <xsd:restriction base="xsd:decimal">
  <xsd:totalDigits value="16"/>
 </xsd:restriction>
</xsd:simpleType>

but this does not work, since it wont accept scientific notation ('E' or 'e' notation). I also tried:

<xsd:simpleType name="DecimalString">
  <xsd:restriction base="xsd:double"/>
</xsd:simpleType>

But not only does it accept the NaN/Inf special values but it also does not allow for specifying a totalDigits value of 16.

How would one specify such validation rules in XSD ?


Solution

  • A possible solution may be:

    <xsd:simpleType name="DecimalString">
     <xsd:restriction base="xsd:string">
      <xsd:pattern value="[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"/>
      <xsd:maxLength value="16" />
     </xsd:restriction>
    </xsd:simpleType>
    

    Based from: