Hi there,

I know I left out a lot but you have completely correctly understood my
question in your response. I was not exactly asking about the property but
it was good of you to comment on that as well. The behaviour you describe is
exactly what happens, but here is where my question comes in. Is there any
way to get Castor to add a NULL value even though there is no value (i.e.
the element is present but empty)?? 

Or will this always be considered different from NULL (i.e. no element at
all)?? Is there any easy way to make these two the same? I saw someone else
that had extended the Marshaller class for something similar which is
something I can do but I would prefer not to.

Definiton of element:

<xs:element name="SomeNiceElementName" minOccurs="0">
  <xs:annotation>
    <xs:documentation/>
  </xs:annotation>
  <xs:simpleType>
    <xs:restriction base="xs:integer">
      <xs:totalDigits value="5"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

Some additional info. This is an element not defined by me. The problem we
have is something I am simply dabbling with on the side, I don't know enough
of XML schemas to say if that is poorly written or not. I also understand
that not having the element present in the XML vs. getting an empty element
in the XML is not the same thing, I would just like to know if there is a
nice and simple way of making it the same thing (usually I have little or no
use for an empty string "" or 0 and would in many instances always want to
set NULL to an attribute that receives this).

Thanks for the answer,

Archie


Werner Guttmann wrote:
> 
> Hi Archie,
> 
> It looks like you are talking about the following property
> 
> # Selects use of Object Wrappers instead of primitives (e.g
> java.lang.Float
> # instead of float).
> # False by default.
> #
> #org.exolab.castor.builder.primitivetowrapper=false
> 
> as defined in the default *castorbuilder.properties* file packaged with
> the codegen JAR. As such I wonder whether you are using a mapping file
> based approach for XML data binding, or whether you are starting with an
> XML schema and generate Java code from it.
> 
> Having said that, let's look at this in a more general context. When an
> XML schema defines an element (definition) as optional, the idea is that
> it's use is optional; so it either will be present or it won't. Once it
> is present in the corresponding XML document, it is assumed as present,
> and a value will be 'deduced' during unmarshalling. If there's no value
> (which obviously does *not* match your XML schema), a default value will
> be 'injected' in the Java property that corresponds to your element
> definition. For a primitive type (int, long, ....), this means that a
> value of '0' will be set. For primitive wrappers I am not sure, but I
> think that the same will happen, as your XML document instance actually
> comes with the element being defined (though empty).
> 
> What does the element definition precisely look like ?
> 
> Werner
> 
> azimo wrote:
>> Hi all,
>> 
>> I have a schema which defines an element as optional. Sometimes this
>> element
>> is not present in the XML that I receive in which case Castor works just
>> fine and the object generated in my Java code contains NULL for the given
>> element. Sometimes however, the XML contains an empty start-end tag which
>> (since my element is numeric) generates the default value of 0. Castor
>> properties has the setting primitivestowrapper set to true so I would
>> like
>> NULL for this as well. Is there any way to make sure that Castor sees an
>> empty start-end tag the same way as if it wasn't present at all??
>> 
>> I've read the documentation and can't find it myself if there is.
>> 
>> Thanks in advance,
>> 
>> Archie
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
> 
>     http://xircles.codehaus.org/manage_email
> 
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Unmarshalling-XML-with-null-values--tp16993226p17019082.html
Sent from the Castor - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to