【发布时间】:2020-10-28 22:08:19
【问题描述】:
我尝试使用xs:assert 根据两个属性的值进行验证,但未成功。我不断得到
s4s-elt-must-match.1:data的内容必须匹配(annotation?, (simpleType | complexType)?, (unique | key | keyref)*))。发现问题始于: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里面的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: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>
【问题讨论】:
标签: xml xsd xsd-validation xml-validation xsd-1.1