tags:

views:

35

answers:

2

Hello.

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?

+2  A: 

Hi,

<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.

kasten
I would rather use base as decimal rather than float in this case.
YoK
I'd say you've learned that bit of XSD then :). Either an xs:float or an xs:decimal would work given the original question.
Nic Gibson
+1  A: 

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>
YoK