Java Mailing List Archive

http://www.junlu.com/

Home » user.castor »

Re: [castor-user] Factorization properties of XML

Werner Guttmann

2009-11-17


Author LoginPost Reply
Hi,

there is not a straight-forward solution for this problem, as XML
artefacts such as <area> and <country> are not simply structural
artefacts, but carry additional information.

For the <cities>, you could have a look at the location attribute as
described at

http://www.castor.org/reference/html-single/index.html#xml.mapping.mappingfile.locationattribute

but for the remainder, I guess you will have to use custom-developed
FieldHandlers.

Regards
Werner

Guillaume Schaeffer wrote:
> Hello,
>
>
> I am currently trying to use castor for XML binding
>   The problem is that I want to use the factorization properties of XML
>   without having to create collections in mybinded classes. Here is an
>   example:
>   I have the following XML:
>   <cities>
>     <area zone="1">
>       <country code="FR">
>         <city>
>           <code>NCE</code>
>           <zipcode>06000</zipcode>
>         </city>
>         <city>
>           <code>PAR</code>
>           <zipcode>75000</zipcode>
>         </city>
>       </country>
>       <country code="DE">
>         <city>
>           <code>BER</code>
>           <zipcode>123456</zipcode>
>         </city>
>       </country>
>     </area>
>     <area zone="2">
>       <country code="US">
>         <city>
>           <code>NYC</code>
>           <zipcode>111111</zipcode>
>         </city>
>         <city>
>           <code>LAX</code>
>           <zipcode>222222</zipcode>
>         </city>
>       </country>
>     </area>
>   </cities>
>
>   Areas, countries and cities can all be repeated.
>   I would like to map this XML into the following class:
>
>   public class City {
>     public int Zone;
>     public String Country;
>     public int Zipcode;
>     public String Code;
>   }
>
>   The example would then produce a cities class having a collection of
> City
>   objects as follows:
>   City object 1 : Zone=1, Country=FR, Zipcode=06000, Code=NCE
>   City object 2 : Zone=1, Country=FR, Zipcode=75000, Code=PAR
>   City object 3 : Zone=1, Country=DE, Zipcode=123456, Code=BER
>   City object 4 : Zone=2, Country=US, Zipcode=111111, Code=NYC
>   City object 5 : Zone=2, Country=US, Zipcode=222222, Code=LAX
>
>   I haven't found a basic way to do this until now. What I can do easily
> is to
>   create a cities class with a collection of areas, having themselves a
>   collection of countries...
>   Is there a direct way to get City objects as described ?
>
>
>   Regards,
>
>   G. Schaeffer

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

  http://xircles.codehaus.org/manage_email


©2008 junlu.com - Jax Systems, LLC, U.S.A.