XSD 1.1断言放在哪里?

问题描述

我尝试基于两个属性的值使用xs:assert进行验证失败。我不断得到

s4s-elt-must-match.1data内容必须与(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?,(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>

解决方法

可能的问题:

  1. 确保您的XSD处理器支持XSD 1.1。
  2. 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>