>>From general perspective I can say that empty string is a valid string - it's a string with length 0.
>But other types are other types and empty value doesn't make any sense and invalid indeed.

>I don't see any inconsistency at all.
>I would be really surprised if there's a switch you're looking for.

Good point, and that seems to be why it fails, however nulls should not be interpreted the same as an empty string so there still seems to be an inconsistency.  The datatypes string and integer used in the examples below are both primitive types according to the XML Schema definition, and they are, at least when the document is created, treated the same in that firstChild of the node is null.  However when the document is validated, the exception thrown is because of the datatype (cvs-type.3.1.3) rather than because it fails minOccurs (cvs-complex-type.2.4.a) for non-strings if the element is empty, but not for strings.
 
 
Here are some examples :
 
This is an excert from the schema for the Name element:

<xsi:element name="Name" type="xsi:string" minOccurs="0" />

If I define Name as a string, the following will validate:
 
<Name></Name>  --> firstChild=null
<Name/>              --> firstChild=null
 
The following also parses, with firstChild set to DeferredTextImpl
<Name>1</Name> --> firstChild= DeferredTextImpl
 
If I change minOccurs to 1, and the <Name> element is not included the validation fails with:
 
[org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content starting with element

However if I change the datatype to integer, only the last example would parse, the others fail as below, although they are also null as with strings.

[org.xml.sax.SAXParseException: cvc-type.3.1.3: The value '' of element 'NAME' is not valid.]

Therefore it seems that the validation order is such that minOccurs is checked after the datatype validation, with the added twist that somehow strings, while also a primitive, are considered valid if null, while other types, such as integer, are not. 

-Mike

 


Ender Oezguer wrote:
Hi,

same case for e.g. 'xs:int' and 'xs:float'. Is there a switch for the validator to handle empty values ? Or any other ideas ?

Ender



O'Keeffe, Michael wrote:
With String datatypes, if the element has an attribute with minOccurs="0",
and the tag is there in the XML, but there is no value, validation is
successful.
However, when I run schema validation where the tag is there but the value
is empty, I will get a schema validation error.  Here is an example:

Here's the schema fragment:
        <element name="FOO_DATE" minOccurs="0" type="date" />
Here a fragment of the XML with FOO_DATE:
        <FOO_DATE/>

Here is the error:
cvc-type.3.1.3: The value '' of element 'FOO_DATE' is not valid.

The only way this will successfully validate is if the tag <FOO_DATE/> is
not in the xml document at all.

Is this the way it is supposed to work?  It doesn't seem consistent with
other datatypes.

-Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



.................................................................
Ender Özgür            neofonie GmbH        Tel: +49.30.24627-329
Softwareentwicklung    Robert-Koch-Platz 4  FAX: +49.30.24627-120
[EMAIL PROTECTED]    D-10115 Berlin       Web: www.neofonie.de



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--

Maksym Kovalenko
Software Engineer
Marketswitch Corporation
http://www.marketswitch.com
108 Powers Court, Suite 225
Dulles, VA 20166
Phone: +1 (703) 444-6750 ext. 302
Fax: +1 (703) 444-6812


Reply via email to