【问题标题】:How to make an attribute of multiple enumerations? schema XSD如何制作多个枚举的属性?架构 XSD
【发布时间】:2018-10-25 14:15:33
【问题描述】:

我想建立一个数据库,其中有一些产品在日本、北美和欧盟的发布日期。 我想让它的方式是,如果某个日期在同一个产品中重复,我可以将区域分组到一个元素中,如下所示:

<releasedate>
     <zone zone="JP">30/08/1987</zone>
     <zone zone="NA|EU">22/11/1987</zone>
</releasedate>

在架构中我有以下代码:

<xsd:attribute name="zone">
 <xsd:simpleType>
  <xsd:restriction base="xsd:string">
   <xsd:enumeration value="JP"/>
    <xsd:enumeration value="NA"/>
    <xsd:enumeration value="EU"/>
   </xsd:restriction>
  </xsd:simpleType>
 </xsd:attribute>

还尝试制作像“JP|NA|UE”和“(JP|NA|UE){1,3}”这样的模式。没有一个对我有用,我不知道我是否使用了错误的方式来分隔值,但我尝试了管道 |并且属性中还有空格

【问题讨论】:

    标签: xml xsd attributes schema restriction


    【解决方案1】:

    你可以定义一个xsd:simpleType:

    <xsd:simpleType name="location">
      <xsd:restriction base="xsd:string">
        <xsd:pattern value="((^|\|)(JP|NA|EU))+$"/>
      </xsd:restriction>
    </xsd:simpleType>
    

    pattern value 中的正则表达式将匹配 JPJP|NAJP|NA|EU 等值以及所有其他可能的组合。

    那么你只需要将属性的值限制为location

    <xsd:attribute name="zone" type="location"/>
    

    【讨论】:

      猜你喜欢
      • 2012-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-16
      相关资源
      最近更新 更多