【问题标题】:Where to place an XSD 1.1 assert?在哪里放置 XSD 1.1 断言?
【发布时间】:2020-10-28 22:08:19
【问题描述】:

我尝试使用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?, (simpleType | complexType)?, (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>

【问题讨论】:

    标签: xml xsd xsd-validation xml-validation xsd-1.1


    【解决方案1】:

    可能的问题:

    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>
    

    【讨论】:

    • 恐怕将它移入 complexType 只会导致不同的错误。我已将其添加到我的问题中。谢谢
    • 哎呀,我忽略了这一点。我检查 Eclipse/Java 是否支持 XSD 1.1。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-21
    • 2020-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多