XML Schema如何声明价格和货币

我正在创建一个存储房屋信息的 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>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念
xml文件介绍及使用
xml编程(一)-xml语法
XML文件结构和基本语法
第2章 包装类
XML入门的常见问题(二)
Java对象的强、软、弱和虚引用
JS解析XML文件和XML字符串详解
java中枚举的详细使用介绍
了解Xml格式
XML入门的常见问题(四)
深入SQLite多线程的使用总结详解
PlayFramework完整实现一个APP(一)
XML和YAML的使用方法
XML轻松学习总节篇