Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
my xsd is this:

XML
<?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 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
Posted
Updated 14-Oct-14 10:04am
v4
Comments
Sergey Alexandrovich Kryukov 14-Oct-14 12:34pm    
Do you want to tread Decimal element as nullable?
—SA
Maciej Los 14-Oct-14 16:11pm    
Does not work is not informative at all!

An element like
XML
<FLG_SUPERVISIOR></FLG_SUPERVISIOR>
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...
XML
<FLG_SUPERVISIOR xsi:nil="true"></FLG_SUPERVISIOR>
An other option is to set minOccurs to 0 and remove the element completely when it is null...
 
Share this answer
 
Comments
Maciej Los 15-Oct-14 1:48am    
5ed!
Kornfeld Eliyahu Peter 15-Oct-14 8:37am    
Thank you!
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[^]
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 14-Oct-14 16:29pm    
Good suggestion about xsd.exe...
You may also add this link to see how null values are working in xml/xsd...http://www.w3.org/TR/xmlschema-0/#Nils
Maciej Los 15-Oct-14 1:47am    
Thank you ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900