Hi Alberto,

If you want to distinguish between these different instances of the 
UnidadeMedida date you need to use different element names - otherwise 
there's no way for JiBX to tell which instance is meant to go where. You 
could do this by changing the <mapping> definition for the UnidadeMedida 
data structure to an abstract mapping, and then using an element name on 
each of the <structure> references.

If you want to keep the element name the same, the other alternative is 
to change the order of these instances in the XML - make all the 
required ones first, and put the optional instance last. That way 
they'll be populated correctly.

While you're at it, you probably also want to remove the 
usage="optional" on all the required instances.

Hope this helps,

  - Dennis

Dennis M. Sosnoski
SOA and Web Services in Java
Training and Consulting
http://www.sosnoski.com - http://www.sosnoski.co.nz
Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117



Alberto Ivo wrote:
> Hello,
>
> I'm having a huge problem with Jibx and I have tried many things but 
> unsuccessful... My doubt is the following:
>
> In my entity I have *5* structure (all of the same type: *UnidadeMedida*):
>
> <structure field="unmeCdDensidadeOleo" usage="optional" /> (1)
> <structure field="unmeCdTempSepara" usage="optional" /> (2)
> <structure field="unmeCdPressMont" usage="optional" /> (3)
> <structure field="unmeCdPressJusante" usage="optional" /> (4)
> <structure field="unmeCdPressSepara" usage="optional" /> (5)
> <structure name="itemMedicaoOleoGases" usage="optional"> (6)
>
> The first structure unmeCdDensidadeOleo can be null. The others are 
> mandatory. And when I *don't* put a value for it, my generated XML 
> file is like this:
>
> <UnidadeMedida>
>      <unmeCdUnidade>20</unmeCdUnidade>      *(2)*
> </UnidadeMedida>
> <UnidadeMedida>
>      <unmeCdUnidade>46</unmeCdUnidade>      *(3)*
> </UnidadeMedida>
> <UnidadeMedida>
>      <unmeCdUnidade>46</unmeCdUnidade>      *(4)*
> </UnidadeMedida>
> <UnidadeMedida>
>      <unmeCdUnidade>46</unmeCdUnidade>      *(5)*
> </UnidadeMedida>
>   the (1) is null
>
> Note that it was generated only 4 tags for <UnidadeMedida> instead of 
> 5. My problem is: when I import the XML file, it throws the value in 
> the 1,2,3,4 when should be 2,3,4,5.
>
> I don't know if you understand me... but the fact is, I want that 
> appears the 5 <UnidadeMedida> because the XML doesn't know which one 
> is the correct attribute.
>
> thanks very much!
>
> -- 
> Alberto Ivo Vieira
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> Stay on top of everything new and different, both inside and 
> around Java (TM) technology - register by April 22, and save
> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
> 300 plus technical and hands-on sessions. Register today. 
> Use priority code J9JMT32. http://p.sf.net/sfu/p
> ------------------------------------------------------------------------
>
> _______________________________________________
> jibx-users mailing list
> jibx-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jibx-users
>   

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to