按架构XSD检查属性值

时间:2017-11-13 07:24:48

标签: xml xsd

我需要检查“book”(root)元素的属性值“id”。

如果“id”值以三个零结尾(id =“****** - 000”),那么另一个属性“book-type”应该是“book”,否则它应该是“chapter”。

这是我的xml看起来像:

<book id="201019894-000" book-type="book" xsi:noNamespaceSchemaLocation="schema.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<book-meta>
<title-group>...

是否有可能在Schema(xsd)中检查上述条件。

请指导我..

由于

1 个答案:

答案 0 :(得分:1)

无法在XSD 1.0中完成。

在XSD 1.1中,您可以使用诸如

之类的断言来完成此操作
<xs:assert test="if (ends-with(@id, '-000') then @book-type='book' else @book-type='chapter'"/>
相关问题