【发布时间】:2012-02-29 07:52:55
【问题描述】:
从这个例子:
<cost isoCode="GBP">27.45</cost>
如何定义属性类型并将“27.45”限制为浮点类型?
我一直在尝试使用混合的 ComplexType,但没有任何运气!
谢谢。
【问题讨论】:
-
我建议永远不要使用 float 之类的货币价值;而是使用小数或整数。
标签: xml xsd complextype
从这个例子:
<cost isoCode="GBP">27.45</cost>
如何定义属性类型并将“27.45”限制为浮点类型?
我一直在尝试使用混合的 ComplexType,但没有任何运气!
谢谢。
【问题讨论】:
标签: xml xsd complextype
您可以使用xs:simpleContent 来执行此操作。下面是起点。
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="cost">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:float">
<xs:attribute name="isoCode" type="isoCodeType" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:simpleType name="isoCodeType">
<xs:restriction base="xs:string">
<xs:enumeration value="GBP" />
<xs:enumeration value="other" />
</xs:restriction>
</xs:simpleType>
</xs:schema>
【讨论】: