在XML架构十进制:指定一个xs小数位的量 [英] Specify amount of decimal places of an xs:decimal in an XML schema

查看:140
本文介绍了在XML架构十进制:指定一个xs小数位的量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 有没有一种方法来指定小数点后的 XS量:小数应该有一个XML架构

  2. 有没有什么办法来控制,使用.NET的 XML *** 属性?

解决方案

您可以创建扩展小数的自定义类型,并指定参数fractionDigits 这样的位数:

 < XS:简单类型名称=twoPlacesDecimalID =twoPlacesDecimal>
    < XS:限制基地=XS:十进制>
        < XS:参数fractionDigits固定=真值=2/>
    < / XS:限制>
< / XS:简单类型>
 

您可以指定使用 XmlAttribute(数据类型=值)的一个属性的数据类型可惜这次只支持内置数据类型。从我读的来源,如果你有一个自定义的数据类型,你会得到一个异常。

  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.

这篇关于在XML架构十进制:指定一个xs小数位的量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆