Hi,

Yes, I've thought about creating classes for LEVEL-2 and LEVEL-3, but I was
curious if there is a better way.

Why I need these empty levels, well, "rebuilding" old XML based application
and that's its API :-(

Thanks a lot.

     Pat

On Mon, 29 Jan 2007 15:02:02 +0100, Werner Guttmann wrote
> Hi,
> 
> Creating XML such as ...
> 
> <LEVEL-1>
>    <LEVEL-2>
>       <LEVEL-3/>
>    </LEVEL-2>
> </LEVEL-1>
> 
> Does not really make sense if the underlying XML artefact (the 
> element <str>) will not be created as a result of marshalling. By 
> default, if the instance value of the String property 'str' equals 
> to 'null', Castor will not marshal the element at all (unless you 
> make the element required and nillable, in which case it will 
> marshall an empty element <str/> within the location given).
> 
> I guess it is important to to acknowledge that the XPATH specified 
> within a location attribute is a prefix only, and as such follows 
> the default rules of marshalling instance members (incl. Dealing 
> with nulls). In other words, if the instance member will not be 
> marshalled, the prefix won't be marshalled either.
> 
> Having said that, you do not have to use a location attribute, even 
> though it is very convenient, as it allows you to work with 
> shortcuts. As this mechanism does not work for your scenario, why 
> not create classes for <LEVEL-2> and <LEVEL-3> and map them 
> accordingly ?
> 
> Regards
> Werner
> 
> > -----Original Message-----
> > From: pat [mailto:[EMAIL PROTECTED] 
> > Sent: Montag, 29. Jänner 2007 13:52
> > To: Castor Users
> > Subject: [castor-user] keeping mapping elements when they are 
> > not present
> > 
> > Hi all,
> > 
> > I have question about Castor XML mapping.
> > 
> > Introduction:
> > public class Clazz {
> >  private String str;
> >  public String getStr() {...}
> >  public void setStr(String str) {...}
> > }
> > 
> > Clazz mapping xml fragment:
> > <class name="Clazz">
> >  <map-to xml="LEVEL-1"/>
> >  <field name="str" type="java.lang.String">
> >     <bind-xml name="str" node="element" 
> > location="LEVEL-2/LEVEL-3"/>  </field> </class>
> > 
> > Problem:
> > When the str field isnot null, then the XML tree structure is 
> > correct for me:
> > <LEVEL-1><LEVEL-2><LEVEL-3><str>...</str></LEVEL-3></LEVEL-2><
> > /LEVEL-1>
> > 
> > But when the str field is null, then the structure is collapsed to:
> > <LEVEL-1/>
> > 
> > And I need to push Castor to this structure (and best of all 
> > is to do it with mapping and without coding):
> > <LEVEL-1><LEVEL-2><LEVEL-3/></LEVEL-2></LEVEL-1>
> > 
> > How can I do this ???
> > 
> > Thanks a lot for the response.
> > 
> >    Pat
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> > 
> >     http://xircles.codehaus.org/manage_email
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
> 
>     http://xircles.codehaus.org/manage_email


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

    http://xircles.codehaus.org/manage_email

Reply via email to