【问题标题】:XML Schema Restriction With Attribute带有属性的 XML 模式限制
【发布时间】:2013-03-15 20:50:10
【问题描述】:

在 XML Schema 中,如何使元素 Age 具有 restriction 以允许写入最大值为 10 和最小值为 1 的整数,在元素 Age 内部以及元素 Age 具有属性?

<xsd:element name="Age">
  <xsd:complexType>
here i want to have restriction to control max and min value inside Age element
    <xsd:attribute name="type" type="xsd:string" use="required" />
  </xsd:complexType>
</xsd:element>

没有警告的 XML 代码

<Age type="sth">
 5 
</Age>

带有警告的 XML 代码

<Age type="sth">
 22
</Age>

【问题讨论】:

    标签: xml xsd


    【解决方案1】:

    这被称为“内容简单的复杂类型”。这是一个例子:

    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base="one-to-ten">
          <xs:attribute name="type" type="xs:string" use="required"/>
        </
      </
    </
    
    <xs:simpleType name="one-to-ten">
      <xs:restriction base="xs:integer">
        <xs:minInclusive value="1"/>
        <xs:maxInclusive value="10"/>
      </
    </
    

    【讨论】:

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