xsd不能使用可空值 [英] xsd doesn't work with nullable value

查看:367
本文介绍了xsd不能使用可空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

i在c#win应用程序中用xsd验证我的Xml文件有问题。

i用 nillable =自定义我的元素xsd true但不起作用并给我错误:

hello,
i have a problem to validate my Xml file with xsd in c# win application.
i have customize my element xsd with nillable="true" but doesn't work and gives me error:

The element 'FLG_SUPERVISOR' is not valid. value '' is not valid for the data type 'http://www.w3.org/2001/XMLSchema:decimal' - The string \" \ "is not a valid Decimal value

我的xsd是这样的:



my xsd is this:

<?xml version="1.0" encoding="Windows-1252"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"

    xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="DocumentElement">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" name="UserSettings" >
          <xs:complexType>
            <xs:sequence>
              <xs:element name="ID_UTENTE" minOccurs="1" maxOccurs="1" type="xs:decimal" />
              <xs:element name="ID_GRUPPO" minOccurs="1" maxOccurs="1" type="xs:decimal" />
              <xs:element name="NOME_UTENTE" minOccurs="1" maxOccurs="1" type="xs:string" />
              <xs:element name="PASSWORD_UTENTE" minOccurs="1" maxOccurs="1" type="xs:string" />
              <xs:element name="FLG_ABILITATO" nillable="true" minOccurs="1" maxOccurs="1" />
              <xs:element name="DES_UTENTE" type="xs:string" />
              <xs:element name="ACRONIMO" type="xs:string" />
              <xs:element name="FLG_SUPERVISOR" nillable="true" minOccurs="0" maxOccurs="1"
   type="xs:decimal" />







i设置了nillable =true但是如果我的 FLG_SUPERVISORE xml中的值为空(null)给出了这个错误:

如何更改我的xsd以启用blach / null值?

nillable =true在其他元素的情况下不起作用)

非常感谢




i have set nillable="true" but if my FLG_SUPERVISORE value in xml is blank (null) gives me this error:
how can i change my xsd to enable blach/null value?
(nillable ="true" doesn't work in no other element case)
thanks a lot

推荐答案

<FLG_SUPERVISIOR></FLG_SUPERVISIOR>

不会声明null元素,而是一个空元素(0长度字符串)。

创建一个exiting元素你可以明确地声明它...

does not declare a null element, but an empty element (0 length string).
To make an exiting element that is nullable you have explicitly state it...

<FLG_SUPERVISIOR xsi:nil="true"></FLG_SUPERVISIOR>

另一个选项是将minOccurs设置为0并在它为null时完全删除元素...

An other option is to set minOccurs to 0 and remove the element completely when it is null...


如果你有一个 *。xml 文件或类定义,我建议使用 xsd.exe工具 [ ^ ],可让您创建 * .xsd 文件。

其他网站,请看这个: Nillable属性绑定支持 [ ^ ]
If you have got an *.xml file or class definition, i'd suggest to use xsd.exe tool[^], which enables you to create *.xsd file.
On the other site, please see this: Nillable Attribute Binding Support[^]


这篇关于xsd不能使用可空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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