在哪里放置 XSD 1.1 断言?
Where to place an XSD 1.1 assert?
我尝试使用 xs:assert
根据两个属性的值进行验证,但未成功。我不断收到
s4s-elt-must-match.1
: The content of data
must match (annotation?, (simpleType | complexType)?, (unique | key | keyref)*))
. A problem was found starting at: assert
.
我查看了一堆问题。我什至复制了给出的答案之一,但即使它给出了同样的错误。它告诉我测试的格式无效,但我找不到任何不同的例子。谁能告诉我我做错了什么?
TIA
这是我复制的答案,内联错误作为注释:
<?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 中的断言,显示不同的错误。
<?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
内:
变化自
<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>
我尝试使用 xs:assert
根据两个属性的值进行验证,但未成功。我不断收到
s4s-elt-must-match.1
: The content ofdata
must match(annotation?, (simpleType | complexType)?, (unique | key | keyref)*))
. A problem was found starting at:assert
.
我查看了一堆问题。我什至复制了给出的答案之一,但即使它给出了同样的错误。它告诉我测试的格式无效,但我找不到任何不同的例子。谁能告诉我我做错了什么?
TIA
这是我复制的答案,内联错误作为注释:
<?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 中的断言,显示不同的错误。
<?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
内:
变化自
<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>