加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

XML Schema如何声明价格和货币

发布时间:2020-12-16 07:51:35 所属栏目:百科 来源:网络整理
导读:我正在创建一个存储房屋信息的 XML模式. 我想存储价格和货币. 在我看来,通过将货币作为价格元素的属性来声明这一点是有道理的. 此外,我想将可以作为货币输入的值限制为英镑,欧元或美元. 例如: price currency="euros"10000.00/price 所以目前我在我的XML Sc
我正在创建一个存储房屋信息的 XML模式.

我想存储价格和货币.

在我看来,通过将货币作为价格元素的属性来声明这一点是有道理的.

此外,我想将可以作为货币输入的值限制为英镑,欧元或美元.

例如:

<price currency="euros">10000.00</price>

所以目前我在我的XML Schema中声明这个:

<!-- House Price,and the currency as an attribute -->
<xs:element name="price">
    <xs:complexType>
        <xs:attribute name="currency">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:enumeration value="pounds" />
                    <xs:enumeration value="euros" />
                    <xs:enumeration value="dollars" />
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
    </xs:complexType>
</xs:element>

我对此有这样的问题:

>我不确定这是否会将属性元素限制为英镑,欧元或美元
>我似乎无法将价格上的类型指定为double,因为我希望由于错误:

Element 'price' has both a 'type' attribute and a 'anonymous type' child. Only one of these is allowed for an element.

我应该保持简单并将它们声明为单独的元素:

<price>10000.00</price>
<currency>euros</currency>

……还是我走在正确的道路上?

以下定义了具有xs:double值的price元素,其中currency值的值限制为:磅,欧元或美元.
<xs:element name="price">
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="xs:double">
                    <xs:attribute name="currency">
                        <xs:simpleType>
                            <xs:restriction base="xs:string">
                                <xs:enumeration value="pounds" />
                                <xs:enumeration value="euros" />
                                <xs:enumeration value="dollars" />
                            </xs:restriction>
                        </xs:simpleType>
                    </xs:attribute>
                </xs:extension>
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读