XSD:属性值的整数范围取决于其他元素?

问题描述 投票:0回答:1

在 XML 文档(使用版本 1.1)中,一个元素

random
有两个整数: 一个整数
start
通常应该只具有
min=1
max=9
之间的值范围。和一个整数
end
总是应该更大然后从
max=10
的最大值开始。被这样定义:

    <xs:complexType name="random">
        <xs:attribute name="start">
            <xs:simpleType>
                <xs:restriction base="xs:integer">
                    <xs:minInclusive value="1"/>
                    <xs:maxInclusive value="9"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
        <xs:attribute name="end">
            <xs:simpleType>
                <xs:restriction base="xs:integer">
                    <xs:minInclusive value="2"/>
                    <xs:maxInclusive value="10"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
        <xs:assert test="@start le @end"/>
    </xs:complexType>

但是现在在一些罕见的情况下,当另一个元素中存在属性

bigValue
时,我希望这些整数实际上能够具有更高的值。例如,在这种情况下,
start
的值为 20,
end
的值为 50:

<annotation extended='bigValue'/><random start='20' end='50'/>

有什么方法可以做到这一点而不必更改

start
end
的值范围(因为在几乎所有其他情况下,它不应该大于9或10)。例如,这可以通过断言来实现吗?还是这根本不可能,更好的方法是在
bigValue
不存在的情况下通过断言限制最大值?

xml integer attributes range assert
1个回答
0
投票

如果该值可以大于 10(这有多“罕见”真的无关紧要),那么您将不得不删除 maxInclusive 并将约束放在

xs:assert
中的包含元素上,其中
 bigValue
属性可见。

© www.soinside.com 2019 - 2024. All rights reserved.