在哪里放置XSD 1.1断言?

3
我试图使用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>

编辑:这里将assert放在complexType中,显示不同的错误。

<?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个回答

2

可能存在的问题:

  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>

to

  <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>

很抱歉,将其移动到complexType内部只是导致了不同的错误。我已经将此添加到我的问题中。谢谢。 - undefined
糟糕,我忽略了这一点。让我检查一下Eclipse/Java是否支持XSD 1.1。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接