带有属性的 XML 模式限制 [英] XML Schema Restriction With Attribute

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

问题描述

在XML Schema中,如何使元素Age具有限制,允许在元素Age<中写入最大值为10,最小值为1的整数/code> 而且元素 Age 有属性?

In XML Schema, how to make element Age to have restriction to allow writing integer with maximum value of 10 and minimum of 1, inside element Age but also element Age to have attribute ?

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

XML Code with no warning

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

带有警告的 XML 代码

XML Code with warning

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

推荐答案

这被称为具有简单内容的复杂类型".举个例子:

This is called a "complex type with simple content". Here's an example:

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

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

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