I'm trying to create a XSD schema rule that allows the following:
我正在尝试创建一个允许以下内容的XSD架构规则:
<Polynom>
<Order>
<Coefficients>
<Coefficient>0</Coefficient>
</Coefficients>
<Coefficients>
<Coefficient>1</Coefficient>
<Coefficient>0</Coefficient>
</Coefficients>
<Coefficients>
<Coefficient>3</Coefficient>
<Coefficient>2</Coefficient>
<Coefficient>1</Coefficient>
</Coefficients>
</Order>
</Polynom>
Now if it was only this it would be simple, however it should be possible to vary the amount of Coefficients
. So if I add another one, that one MUST have four Coefficient
现在如果它只是这样简单,但应该可以改变系数的数量。因此,如果我添加另一个,那一个必须有四个系数
I'm not even sure this is possible with xsd?
我甚至不确定这可以用xsd吗?
Update: Just to clarify, the first Coefficients
must have one and exactly one Coefficient
, then n-th Coefficients
in a set of n Coefficents
must have n Coefficient
.
更新:为了澄清,第一个系数必须有一个且恰好是一个系数,那么一组n个系数中的第n个系数必须具有n个系数。
1 个解决方案
#1
0
Your constraint can be expressed in XSD 1.1 using xs:assert
:
您的约束可以使用xs:assert在XSD 1.1中表示:
<?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:element name="Polynom">
<xs:complexType>
<xs:sequence>
<xs:element name="Order">
<xs:complexType>
<xs:sequence>
<xs:element name="Coefficients" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Coefficient" maxOccurs="unbounded"
type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:assert test="every $c in Coefficients satisfies
count($c/Coefficient) = count($c/preceding-sibling::*) + 1"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Your constraint cannot be expressed in XSD 1.0.
您的约束无法在XSD 1.0中表示。
#1
0
Your constraint can be expressed in XSD 1.1 using xs:assert
:
您的约束可以使用xs:assert在XSD 1.1中表示:
<?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:element name="Polynom">
<xs:complexType>
<xs:sequence>
<xs:element name="Order">
<xs:complexType>
<xs:sequence>
<xs:element name="Coefficients" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Coefficient" maxOccurs="unbounded"
type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:assert test="every $c in Coefficients satisfies
count($c/Coefficient) = count($c/preceding-sibling::*) + 1"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Your constraint cannot be expressed in XSD 1.0.
您的约束无法在XSD 1.0中表示。