在哪里放置 XSD 1.1 断言? [英] Where to place an XSD 1.1 assert?

查看:36
本文介绍了在哪里放置 XSD 1.1 断言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 xs:assert 根据两个属性的值进行验证未成功.我不断得到

I'm trying unsuccessfully to use an xs:assert to validate based on the values of two attributes. I keep getting

s4s-elt-must-match.1:data 的内容必须匹配(annotation?, (simpleType | complexType)?, (unique |键 | keyref)*)).从以下位置开始发现问题:assert.

s4s-elt-must-match.1: The content of data must match (annotation?, (simpleType | complexType)?, (unique | key | keyref)*)). A problem was found starting at: assert.

我看了一堆问题.我什至复制了给出的答案之一,但即使它给出了同样的错误.它告诉我测试的格式无效,但我找不到任何不同的示例.谁能告诉我我做错了什么?

I've looked thru a bunch of questions. I even copied one of the answers given, but even it gives the same error. It's telling me the format of the test is invalid, but I can't find any example that does it differently. Can anyone tell me what I'm doing wrong?

TIA

这是我复制的答案,内嵌错误作为注释:

Here's the answer I copied, with the error inline as a comment:

<?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 中的断言,显示了不同的错误.

Here it is with the assert inside the complexType, showing a different error.

<?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 中:
  1. Make sure your XSD processor supports XSD 1.1.
  2. Move the xs:assert element to within 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>

这篇关于在哪里放置 XSD 1.1 断言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆