【问题标题】:Check attribute value by schema XSD通过模式 XSD 检查属性值
【发布时间】:2017-11-13 07:24:47
【问题描述】:

我需要检查“book”(根)元素的属性值“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) 中检查上述条件。

请指导我..

谢谢

【问题讨论】:

    标签: xml xsd


    【解决方案1】:

    无法在 XSD 1.0 中完成。

    在 XSD 1.1 中,您可以使用断言来做到这一点,例如

    <xs:assert test="if (ends-with(@id, '-000') then @book-type='book' else @book-type='chapter'"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多