【发布时间】:2018-02-09 01:41:18
【问题描述】:
我想在我的 XSD 架构中为我的 XML 文档使用条件。
我使用了限制,但它不是很强大。
这是我到目前为止所做的一个示例:
<xs:element name="Matricule">
<xs:complexType>
<xs:sequence>
<xs:element name="valeur">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"></xs:minInclusive>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element type="xs:string" name="backgroundcolor"/>
</xs:sequence>
</xs:complexType>
</xs:element>
这个例子工作正常,但我只检查该值是否大于 0。但我想验证该值是否为整数并且该值是否为空。
也许是这样的:
如果(值 > 0 AND 值
我在谷歌上发现了一个关于断言的主题,所以我阅读了文档并做到了
<xs:element name="Matricule">
<xs:complexType>
<xs:sequence>
<xs:element name="valeur">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"></xs:minInclusive>
**<xs:assertion test="($value mod 10) = 0"/>**
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element type="xs:string" name="backgroundcolor"/>
</xs:sequence>
</xs:complexType>
</xs:element>
但是不行,我老是报错。
具有价值的示例 1:
<racine>
<row>
<Matricule>
<valeur>55</valeur>
<backgroundcolor></backgroundcolor>
</Matricule>
</row>
</racine>
没有价值的例子2:
<racine>
<row>
<Matricule>
<valeur></valeur>
<backgroundcolor></backgroundcolor>
</Matricule>
</row>
</racine>
这两个例子必须是正确的,但这个不是:
<racine>
<row>
<Matricule>
<valeur>gfd</valeur>
<backgroundcolor></backgroundcolor>
</Matricule>
</row>
</racine>
【问题讨论】:
-
“值为空”是什么意思?您想接受什么样的 XML 而您设置的限制又不会接受?断言适用于未得到广泛支持的 XSD 1.1。您可能不想要它,即使它受到支持也不太可能对您有所帮助。
-
好的,我修改了我的帖子,希望你能更好地理解。事实上,我需要使用 xml 验证器来检查我的所有文件
标签: xml xsd schema conditional-statements restrictions