【发布时间】:2018-02-02 17:06:03
【问题描述】:
在 C# win 应用程序中使用 xsd 验证我的 XML 文件时遇到问题。
我已经使用nillable="true" 自定义了我的元素 xsd,但它不起作用并出现错误:
元素“FLG_SUPERVISOR”无效。值 '' 对 数据类型 'http://www.w3.org/2001/XMLSchema:decimal' - 字符串 \" \ "不是有效的十进制值
我的 xsd 是这样的:
<?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" />
我已经设置了nillable="true",但是如果我在 xml 中的FLG_SUPERVISORE 值为空白(null)会给我这个错误:
如何更改我的 xsd 以启用空白/空值?
(nillable ="true" 在没有其他元素的情况下不起作用)。
非常感谢
【问题讨论】:
-
它必须是 nullable="true" 而不是 nillable="true"。
-
如果我写可空的视觉工作室给我错误:在这种情况下不支持可空属性