开发者

Specify amount of decimal places of an xs:decimal in an XML schema

开发者 https://www.devze.com 2023-03-02 04:59 出处:网络
Is there 开发者_如何学运维a way to specify the amount of decimal places an xs:decimal should have in an XML schema?
  1. Is there 开发者_如何学运维a way to specify the amount of decimal places an xs:decimal should have in an XML schema?

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

0

精彩评论

暂无评论...
验证码 换一张
取 消