约束值无效 [英] Invalid Constraint Value

查看:153
本文介绍了约束值无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用生成的.xsd时,我在WebSphere MQ Broker Tool v7.0中收到以下验证错误:

I am receiving the following validation error in the WebSphere MQ Broker Tool v7.0 when working with a generated .xsd:

a-props-correct.2: Invalid value constraint value '0' in attribute 'attrname'.

相关的.xsd文本是该属性的用法:

The relevant .xsd text is the usage of the attribute:

<xsd:complexType name="CTypeContent">
    <xsd:simpleContent>
        <xsd:extension base="xsd:base64Binary">
            <xsd:attribute name="attrname" type="BooleanType" use="optional" default="1" />
        </xsd:extension>
    </xsd:simpleContent>
</xsd:complexType>

属性的定义:

  <xsd:simpleType name="BooleanType">
    <xsd:restriction base="xsd:boolean">
      <xsd:pattern value="0|1" />
    </xsd:restriction>
  </xsd:simpleType>

我已经用Google搜索了,发现了许多关于SOAP之类的讨论,但是这似乎与我的项目有些脱节.我只想确保.xsd中的逻辑是有充分根据的.

I have Googled and found many discussions about SOAP and the like but that seems a bit off my project. I just want to ensure that the logic in the .xsd is well founded.

如果我删除属性的默认部分,错误就会消失.这不是我的解决方案-但这可能有助于诊断.

The error disappears if I remove the default piece of the attribute. This isn't a solution for me - but perhaps it helps in a diagnosis.

推荐答案

XSD代码段有效,因此

The XSD snippets are valid, so the error you're getting makes no sense. I believe it is rather a bug in your WMB software.

您使用的是哪个版本的WMB?

What version of WMB are you using?

由于您似乎可以使用XSD,因此如果不删除默认属性,而尝试将值"0 | 1"中的一个模式重写为两个单独的模式,这也将有助于进行故障排除. ,一个的值为"0",另一个的值为"1".我以前见过来自同一供应商的其他产品,这些产品中与xsd:boolean相关联的模式严重失败.

Since you seem to be able to play with the XSD, it would also help with troubleshooting if instead of removing the default attribute, try to rewrite the pattern from one with the value of "0|1", into two separate patterns, one with a value of "0", and another with the value of "1". I've seen before with other products from the same vendor where patterns associated with xsd:boolean fail miserably.

更新:自发布以来,我一直在研究这种情况和其他类似情况,并意识到模式处理器在验证似乎基本相同的事物的同时会表现出不同的行为:一种根据规范更正但实际上却是正确的模式它描述了一种不可能.这就是关于正确是什么的事情.

UPDATE: Since posting this, I've ran myself into this and other similar scenarios, and realized that schema processors behave differently while validating what seems to be basically the same thing: a schema that correct according to the spec, yet practically it describes an impossibility. And this is where things get interesting as to what correct is.

这种情况可能更微妙,因为它涉及到正确;基本上,如果使用默认值,它将使用相关值的规范表示形式(而不是默认值中的字符串!).由于 1 表示布尔的 True ,因此其规范表示为字符串 true ,该字符串现在显然与模式不匹配(带有词法表示形式-基本上是字符串) 0 | 1 ,这又使这两个不兼容.考虑到PSVI,当应用默认设置时,支持XSD的XML处理器无法创建有效的XML.这就是错误消息的内容.

This case is a bit more subtle maybe, since it involves getting this and this right; basically if a default kicks in, it'll use the canonical representation of the associated value (not the string in the default value!). Since 1 means True for a boolean, the canonical representation of that is the string true which now obviously doesn't match the pattern (which deals with the lexical representation - string basically) 0|1 which in turn makes these two incompatible. Considering PSVI, an XML processor that is XSD aware cannot create valid XML when applying the default. This is what the error message says.

要显示我通常使用的任何XSD处理器未标记的其他不可能,请考虑以下特定代码段:

To show other imposibility that is not flagged by any XSD processor I am typically using, consider this particular snippet:

<xsd:complexType name="Test">
    <xsd:sequence>
        <xsd:element name="Impossible" type="Test"/>
    </xsd:sequence>
</xsd:complexType>
<xsd:element name="Test" type="Test"/>

无法从此XSD创建有效的XML,就像在您的情况下(模式限制为0和1)缺少default ="1"和属性一样.

It is impossible to create a valid XML out of this XSD, just as having a default="1" and attribute missing in your case (of pattern restricted to 0 and 1).

对我来说,这两种情况有点类似于代码编译器(在编译时)捕获零除条件-在可行的情况下.

To me, both scenarios are somewhat similar to a code compiler catching (at compile time) a divide by zero condition - where it can.

这篇关于约束值无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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