Specify amount of decimal places of an xs:decimal in an XML schema
Is there 开发者_如何学运维a way to specify the amount of decimal places an
xs:decimal
should have in an XML schema?Is there any way to control that using .NET's
Xml***
attributes?
You can create a custom type that extends decimal and specify the number of digits in fractionDigits
like this:
<xs:simpleType name="twoPlacesDecimal" id="twoPlacesDecimal">
<xs:restriction base="xs:decimal">
<xs:fractionDigits fixed="true" value="2" />
</xs:restriction>
</xs:simpleType>
You can specify the data type for a property using XmlAttribute(DataType = "value")
but unfortunately this only supports built-in data types. From my reading of the source, if you include a custom data type you'll get an exception.
精彩评论