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 开发者_StackOverflowis 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?
<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.
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>
精彩评论