且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Xml模式中将属性添加到简单类型或将限制添加到复杂类型

更新时间:2021-12-05 00:39:33

要添加必须通过扩展导出的属性,要添加必须通过限制导出的构面.因此,对于元素的子内容,必须分两个步骤完成.该属性可以内联定义:

To add attributes you have to derive by extension, to add facets you have to derive by restriction. Therefore this has to be done in two steps for the element's child content. The attribute can be defined inline:

<xsd:simpleType name="timeValueType">
  <xsd:restriction base="xsd:token">
    <xsd:pattern value="\d{2}:\d{2}"/>
  </xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="timeType">
  <xsd:simpleContent>
    <xsd:extension base="timeValueType">
      <xsd:attribute name="format">
        <xsd:simpleType>
          <xsd:restriction base="xsd:token">
            <xsd:enumeration value="seconds"/>
            <xsd:enumeration value="minutes"/>
            <xsd:enumeration value="hours"/>
          </xsd:restriction>
        </xsd:simpleType>
      </xsd:attribute>
    </xsd:extension>
  </xsd:simpleContent>
</xsd:complexType>