XML Schema 如何通过枚举限制属性 [英] XML Schema How to Restrict Attribute by Enumeration

查看:38
本文介绍了XML Schema 如何通过枚举限制属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 XML 标签

I have the following XML Tag

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

如何将货币属性限制为以下之一:

How do I restrict the currency attribute to one the following:

  • 欧元
  • 美元

价格翻倍?

当我尝试在两者上输入一个类型时,我只是收到一个错误,这是我目前所得到的:

I just get an error when I try to a type on both, here's what I've got so far:

<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>

推荐答案

您的价格定义中似乎缺少数值.请尝试以下操作:

The numerical value seems to be missing from your price definition. Try the following:

<xs:simpleType name="curr">
  <xs:restriction base="xs:string">
    <xs:enumeration value="pounds" />
    <xs:enumeration value="euros" />
    <xs:enumeration value="dollars" />
  </xs:restriction>
</xs:simpleType>



<xs:element name="price">
        <xs:complexType>
            <xs:extension base="xs:decimal">
              <xs:attribute name="currency" type="curr"/>
            </xs:extension>
        </xs:complexType>
</xs:element>

这篇关于XML Schema 如何通过枚举限制属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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