允许的元素值如何依赖于 XSD 中的其他元素值? [英] How can allowed element values depend on other element values in XSD?

查看:29
本文介绍了允许的元素值如何依赖于 XSD 中的其他元素值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下任务(简单版本):用 XSD 温度描述.有最小值、最大值和默认值.默认值应该放在 min...max 值之内.如何用XSD来描述这些东西?

I have a following task (in simple version): Describe in XSD temperatures. There are min, max and default values. Default should be placed inside of min...max values. How to describe these things with XSD?

我的意思是:

Min_Set_Temp [ Integer between 0 and 1000 ]
Max Set Temp [ Integer between 0 and 1000 ]
Default_Set_Temp [ Integer between Min Set Temp and Max Set Temp]

XSD 开始:

<xs:simpleType name="tSetTemperature">
    <xs:restriction base="xs:unsignedShort">
        <xs:minInclusive value="0"/>
        <xs:maxInclusive value="1000"/>
    </xs:restriction>
</xs:simpleType>

<xs:element name="Bake">
  <xs:complexType>
    <xs:sequence>
        <xs:element name="MinSetTemp" type="tSetTemperature"/>
        <xs:element name="MaxSetTemp" type="tSetTemperature"/>
        <xs:element name="DefaultTemp" type="tSetTemperature"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

推荐答案

XSD 1.0

不可能.

可以使用 xs:assert:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
           vc:minVersion="1.1">

  <xs:simpleType name="tSetTemperature">
    <xs:restriction base="xs:unsignedShort">
      <xs:minInclusive value="0"/>
      <xs:maxInclusive value="1000"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:element name="Bake">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="MinSetTemp" type="tSetTemperature"/>
        <xs:element name="MaxSetTemp" type="tSetTemperature"/>
        <xs:element name="DefaultTemp" type="tSetTemperature"/>
      </xs:sequence>
      <xs:assert test="DefaultTemp = MinSetTemp to MaxSetTemp"/>
    </xs:complexType>
  </xs:element>
 </xs:schema>

这篇关于允许的元素值如何依赖于 XSD 中的其他元素值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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