nan
nan

Reputation: 20316

How do I define custom datatype in xsd?

I want to check if a field in my XML is of type positive double/decimal. There is a type="xs:positiveInteger" datatype in XSD but no positive double or decimal. Is there a way to achieve this either by defining custom datatype or some other way?

Upvotes: 3

Views: 4141

Answers (2)

YoK
YoK

Reputation: 14505

You can achieve this by defining decimal datatype with restriction as following.

<xs:simpleType name="positiveDecimal">
  <xs:restriction base="xs:decimal">
    <xs:minInclusive value="0"/>
  </xs:restriction>
</xs:simpleType>

Upvotes: 3

kasten
kasten

Reputation: 628

<xs:element name="data">
  <xs:simpleType>
    <xs:restriction base="xs:float">
      <xs:minInclusive value="0"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

i think this should do it. There may be a shorter way i'm still learning xsd.

Upvotes: 4

Related Questions