有没有一种方法来指定小数点后的 XS量:小数
应该有一个XML架构
有没有什么办法来控制,使用.NET的 XML ***
属性?
您可以创建扩展小数的自定义类型,并指定参数fractionDigits
这样的位数:
< XS:简单类型名称=twoPlacesDecimalID =twoPlacesDecimal>
< XS:限制基地=XS:十进制>
< XS:参数fractionDigits固定=真值=2/>
< / XS:限制>
< / XS:简单类型>
您可以指定使用 XmlAttribute(数据类型=值)的一个属性的数据类型
可惜这次只支持内置数据类型。从我读的来源,如果你有一个自定义的数据类型,你会得到一个异常。
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.