Can XStream read list of two object without a container tag

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Can XStream read list of two object without a container tag

leonardo
my bad xml that have to read is like this:
A-file.xml
<element>
  <obj1 lg="xx">yyy</obj1>
  <obj2 lg="xx">yyy</obj2>
 
  <obj1 lg="xx">yyy</obj1>
  <obj2 lg="xx">yyy</obj2>
 
  <obj1 lg="xx">yyy</obj1>
  <obj2 lg="xx">yyy</obj2>
  ...  
</element>

element tag have a List of 2 tag
like an implicitCollection but without a container:
this will be better
B-file.xml
<element>
  <container>
    <obj1 lg="xx">yyy</obj1>
    <obj2 lg="xx">yyy</obj2>
  </container>
  <container>
    <obj1 lg="xx">yyy</obj1>
    <obj2 lg="xx">yyy</obj2>
  </container>
  <container>
    <obj1 lg="xx">yyy</obj1>
    <obj2 lg="xx">yyy</obj2>
  </container>
  ...  
</element>
but unlikely this is not my xml.

can help me on read A-file.xml?

regards


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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Can XStream read list of two object without a container tag

Jörg Schaible-2
Hi Leonardo,

leonardo wrote:

> my bad xml that have to read is like this:
> A-file.xml
> <element>
>   <obj1 lg="xx">yyy</obj1>
>   <obj2 lg="xx">yyy</obj2>
>  
>   <obj1 lg="xx">yyy</obj1>
>   <obj2 lg="xx">yyy</obj2>
>  
>   <obj1 lg="xx">yyy</obj1>
>   <obj2 lg="xx">yyy</obj2>
>   ...
> </element>
>
> element tag have a List of 2 tag
> like an implicitCollection but without a container:
> this will be better
> B-file.xml
> <element>
>   <container>
>     <obj1 lg="xx">yyy</obj1>
>     <obj2 lg="xx">yyy</obj2>
>   </container>
>   <container>
>     <obj1 lg="xx">yyy</obj1>
>     <obj2 lg="xx">yyy</obj2>
>   </container>
>   <container>
>     <obj1 lg="xx">yyy</obj1>
>     <obj2 lg="xx">yyy</obj2>
>   </container>
>   ...
> </element>
> but unlikely this is not my xml.
>
> can help me on read A-file.xml?

Why don't you write a simple custom converter for the type that is
represented by the element tag? It's then completely up to you, what you do
with the individual child elements. Have a look at the converter tutorial,
it should be really an easy job.

- Jörg


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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Can XStream read list of two object without a container tag

leonardo
Ok I have do and is very simple to write.
thank you.

I notice that at the end of page
http://xstream.codehaus.org/converter-tutorial.html
there was two line swapped:
writer.addAttribute("gender", Character.toString(birthday.getGender()));
Birthday birthday = (Birthday)value;

Il giorno sab, 11/05/2013 alle 13.26 +0200, Jörg Schaible ha scritto:

> Hi Leonardo,
>
> leonardo wrote:
>
> > my bad xml that have to read is like this:
> > A-file.xml
> > <element>
> >   <obj1 lg="xx">yyy</obj1>
> >   <obj2 lg="xx">yyy</obj2>
> >  
> >   <obj1 lg="xx">yyy</obj1>
> >   <obj2 lg="xx">yyy</obj2>
> >  
> >   <obj1 lg="xx">yyy</obj1>
> >   <obj2 lg="xx">yyy</obj2>
> >   ...
> > </element>
> >
> > element tag have a List of 2 tag
> > like an implicitCollection but without a container:
> > this will be better
> > B-file.xml
> > <element>
> >   <container>
> >     <obj1 lg="xx">yyy</obj1>
> >     <obj2 lg="xx">yyy</obj2>
> >   </container>
> >   <container>
> >     <obj1 lg="xx">yyy</obj1>
> >     <obj2 lg="xx">yyy</obj2>
> >   </container>
> >   <container>
> >     <obj1 lg="xx">yyy</obj1>
> >     <obj2 lg="xx">yyy</obj2>
> >   </container>
> >   ...
> > </element>
> > but unlikely this is not my xml.
> >
> > can help me on read A-file.xml?
>
> Why don't you write a simple custom converter for the type that is
> represented by the element tag? It's then completely up to you, what you do
> with the individual child elements. Have a look at the converter tutorial,
> it should be really an easy job.
>
> - Jörg
>
>
> ---------------------------------------------------------------------
> 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 | Threaded
Open this post in threaded view
|

Re: Re: Can XStream read list of two object without a container tag

Jörg Schaible-2
Hi Leonardo,

leonardo wrote:

> Ok I have do and is very simple to write.
> thank you.
>
> I notice that at the end of page
> http://xstream.codehaus.org/converter-tutorial.html
> there was two line swapped:
> writer.addAttribute("gender", Character.toString(birthday.getGender()));
> Birthday birthday = (Birthday)value;

thanks for head's up! Fixed in trunk.

Cheers,
Jörg


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

    http://xircles.codehaus.org/manage_email