4

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

1 回答 1

6

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

<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"/>
  </
</
于 2013-03-15T12:50:10.817 回答