在哪里放置 XSD 1.1 断言? [英] Where to place an XSD 1.1 assert?
问题描述
我尝试使用 xs:assert
根据两个属性的值进行验证未成功.我不断得到
I'm trying unsuccessfully to use an xs:assert
to validate based on the values of two attributes. I keep getting
s4s-elt-must-match.1
:data
的内容必须匹配(annotation?, (simpleType | complexType)?, (unique |键 | keyref)*))
.从以下位置开始发现问题:assert
.
s4s-elt-must-match.1
: The content ofdata
must match(annotation?, (simpleType | complexType)?, (unique | key | keyref)*))
. A problem was found starting at:assert
.
我看了一堆问题.我什至复制了给出的答案之一,但即使它给出了同样的错误.它告诉我测试的格式无效,但我找不到任何不同的示例.谁能告诉我我做错了什么?
I've looked thru a bunch of questions. I even copied one of the answers given, but even it gives the same error. It's telling me the format of the test is invalid, but I can't find any example that does it differently. Can anyone tell me what I'm doing wrong?
TIA
这是我复制的答案,内嵌错误作为注释:
Here's the answer I copied, with the error inline as a comment:
<?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="data">
<xs:complexType>
<xs:attribute name="min" type="xs:int"/>
<xs:attribute name="max" type="xs:int"/>
</xs:complexType>
<xs:assert test="@min le @max"/>
<!--s4s-elt-must-match.1: The content of 'data' must match (annotation?, (simpleType | complexType)?, (unique | key | keyref)*)). A problem was found starting at: assert.-->
</xs:element>
</xs:schema>
这里是 complexType 中的断言,显示了不同的错误.
Here it is with the assert inside the complexType, showing a different error.
<?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="data">
<xs:complexType>
<xs:attribute name="min" type="xs:int"/>
<xs:attribute name="max" type="xs:int"/>
<xs:assert test="@min le @max"/>
<!-- s4s-elt-invalid-content.1: The content of '#AnonType_data' is invalid. Element 'assert' is invalid, misplaced, or
occurs too often. -->
</xs:complexType>
</xs:element>
</xs:schema>
推荐答案
可能的问题:
- 确保您的 XSD 处理器支持 XSD 1.1.
- 将
xs:assert
元素移动到xs:complex
中:
- Make sure your XSD processor supports XSD 1.1.
- Move the
xs:assert
element to withinxs:complex
:
更改自
<xs:element name="data">
<xs:complexType>
<xs:attribute name="min" type="xs:int"/>
<xs:attribute name="max" type="xs:int"/>
</xs:complexType>
<xs:assert test="@min le @max"/>
</xs:element>
到
<xs:element name="data">
<xs:complexType>
<xs:attribute name="min" type="xs:int"/>
<xs:attribute name="max" type="xs:int"/>
<xs:assert test="@min le @max"/>
</xs:complexType>
</xs:element>
这篇关于在哪里放置 XSD 1.1 断言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!