Thank you.
----- Original Message -----
Sent: Tuesday, October 25, 2005 3:12 PM
Subject: RE: nilable and validate()

There is an earlier discussion on this topic, please see:

 

http://www.mail-archive.com/[email protected]/msg00512.html

 

Cezar

 


From: Samuel B. Quiring [mailto:[EMAIL PROTECTED]
Sent: Tuesday, October 25, 2005 3:10 PM
To: [email protected]
Subject: nilable and validate()

 

Greetings,

 

I have a schema fragment that looks like this:

 

<xs:complexType name="HumanNameDataType">
    <xs:sequence>
         <xs:element name="PrefixName" type="glob:StringMin1Max10Type" minOccurs="0"/>
         <xs:element name="FirstName" type="glob:StringMin1Max35Type"/>
         <xs:element name="MiddleName" type="glob:StringMin1Max25Type" minOccurs="0"/>
         <xs:element name="LastName" type="glob:StringMin1Max60Type"/>
         <xs:element name="SuffixName" type="glob:StringMin1Max10Type" minOccurs="0"/>
    </xs:sequence>
</xs:complexType>

 

I'm calling validate() to verify the java object after I fill it with values.  For the three fields with minOccurs="0", if I set value to null validate returns this error:

 

validation error: <xml-fragment xmlns:glob="http://apply.grants.gov/system/GlobalLibrary-V1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <glob:PrefixName>Dr.</glob:PrefixName>

    <glob:FirstName>Emmet</glob:FirstName>

    <glob:MiddleName>T</glob:MiddleName>

    <glob:LastName>Brown</glob:LastName>

    <glob:SuffixName xsi:nil="true"/>

</xml-fragment>,[EMAIL PROTECTED]

[EMAIL PROTECTED]

validationerror: error: cvc-elt.3.1: Element has xsi:nil attribute but is not nillable

 

To deal with this I tried setting the value 3 different ways:

 

name.setSuffixName(null);   -- see above error

name.setSuffixName("");     -- min string length must be 1

do nothing                  -- this works.

 

Only if I did nothing did validate() report no errors.

 

What is the difference between setting a value to null and not setting a value at all?  Is there a configuration parameter I can use to say "setting a value to null is the same as not setting it?"

 

Is this behavior documented somewhere?  I searched the docs but couldn't find anything, but I probably missed it.

 

-Sam

 

Reply via email to