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>

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念