XSD 验证失败,因为 null 值是无效的十进制

发布于 2024-12-25 09:21:32 字数 767 浏览 4 评论 0原文

我在编写有效的 XSD 来描述小数的潜在空值时遇到问题。

我正在尝试验证以下 XML

<RatioDe fieldId="011" nil="true"></RatioDe>

,并且该元素的相应 XSD 描述是

  <xs:element minOccurs="0" maxOccurs="1" name="RatioDe" nillable="true">
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base="xs:decimal">
          <xs:attribute name="fieldId" type="xs:string" />
          <xs:attribute name="nil" type="xs:boolean" />
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>

基本上,错误消息是

元素 'RatioDe' 无效 - 值 '' 不是有效的 'Decimal' -- 字符串 '' 不是有效的十进制值

目前我不知道如何更改我的 xsd 以使 xml 有效。

i have a problem writing a valid XSD which describes a potential null-value for a decimal.

I'm trying to validate following XML

<RatioDe fieldId="011" nil="true"></RatioDe>

and the corresponding XSD description for this element is

  <xs:element minOccurs="0" maxOccurs="1" name="RatioDe" nillable="true">
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base="xs:decimal">
          <xs:attribute name="fieldId" type="xs:string" />
          <xs:attribute name="nil" type="xs:boolean" />
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>

Basically, the errormessage is

The element 'RatioDe' is invalid - The value '' is not a valid 'Decimal' -- The string '' is not a valid decimal value

At the moment i have no further idea what to change in my xsd to make the xml valid.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红衣飘飘貌似仙 2025-01-01 09:21:32

您需要在实例文档中使用 xsi:nil,而不仅仅是 nil,即

<RatioDe fieldId="011" xsi:nil="true"/>

并确保 xsi 前缀在文档(带有 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

You need to use xsi:nil in your instance document, not just nil, i.e.

<RatioDe fieldId="011" xsi:nil="true"/>

And make sure that the xsi prefix is defined somewhere in the document (with xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance")

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文