Keith,
I think the issue is a matter of what Castor's definition of a required
field is.
minOccurs=1 is all about the XML tag: there must be one. It is not a
definition of the content of the tag, which could be empty.
For example, we have a tag defined as such:
<xs:element name="MyTextField" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="20"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Castor generates a validation rule like so:
desc.setRequired(true);
Conversly in XMLFieldDescriptorImpl, Castor has:
if (_required) {
_validator = new FieldValidator();
_validator.setMinOccurs(1);
_validator.setDescriptor(this);
}
The problem is a value of NULL that might come out of a database or
something, has no bearing on the required status of the tag in the XSD. All
the XSD is saying is that the tag should exist. But it could be blank.
Castor, in my mind, erroneously disregards NULL values when it fails to
produce an empty tag.
This is an even bigger problem for numeric or date fields. Null has a
meaning of emptiness that is still valid, yet Castor doesn't generate that
important tag in those cases.
So this is a summary:
- What Castor is doing:
if field = null,
then Castor produces no corresponding tag
- What I think it should be doing:
if field = null
then Castor produces an empty tag (</field>)
- Alternatively, Castor gives us a configurable choice.
The workarounds to deal with this are hugely invasive otherwise and almost
completely negate the benefits Castor provides.
Dan
-----Original Message-----
From: Keith Visco [mailto:kvisco@;intalio.com]
Sent: Wednesday, November 06, 2002 2:52 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] Problem: Castor's handling of nulls when
generating XML
Hi Daniel,
If you're using Castor generated source code, and the tag is required, a
ValidationException should be thrown indicating that a required field is
missing if the field is null. Unless of course you have disabled
validation, in which case there is nothing we can do about that.
If you're using a mapping file you'll have to explicitely say that the
field is required.
If you have validation enabled (it is by default), and you are using
source generation or mapping file with required for the proper fields,
then please provide a test case which demonstrates the problem so that
we can help track down the issue.
Thanks,
--Keith
Daniel Kirkdorffer wrote:
>
> We're running into a situation where we are working with Castor 0.9.4 to
> produce XML. The issue is how Castor deals with nulls. Instead of
> producing empty XML element tags, Castor omits the tag entirely. If the
tag
> was optional this isn't a problem, but when it is required, empty or not,
it
> is a big problem.
>
> Has anyone on this list has had to deal with this before and can suggest a
> solution, or knows of a configuration settings that solves the problem.
>
> Thanks,
>
> Dan
>
> --
> Daniel Kirkdorffer
> Sr. Developer
> Versatile Mobile Systems
> Work: 425-673-5933
> Cell: 206-399-1367
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev