1:N nodes

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

1:N nodes

falcorn
Hi.
I wondering if something like this is possible:
i have xml:
<xml>
    <id>id</id>
    <listOfObjects>
       <someobject>
          <some>2</some>
          <something>df</something>
       </someobject>
       <someobject>
          <some>e</some>
          <something>ef</something>
       </someobject>
    </listOfObjects>
</xml>

but class someobject in java:
class someobject{
    String id;
    String some;
    String something;
}

Is it possible to initialize id at class someobject with value from
xml/value?

Greetings
Piotr Idzikowski


----------------------------------------------------------------------
Poznaj Stefana! Zmien komunikator! >>> http://link.interia.pl/f1924

Reply | Threaded
Open this post in threaded view
|

Re: 1:N nodes

guilherme_silveira
You can create your own converters and use the UnmarshallingContext to
put and get the id as to pass variables around.

ps: isn't the DataHolder missing the remove key?

Guilherme
--
Guilherme Silveira
--------------------------------------------------
[hidden email]
Caelum - Ensino e Solucoes em Java
www.caelum.com.br
Reply | Threaded
Open this post in threaded view
|

RE: 1:N nodes

Jörg Schaible
In reply to this post by falcorn
Piotr Idzikowski wrote on Wednesday, April 19, 2006 1:15 PM:

> Hi.
> I wondering if something like this is possible:
> i have xml:
> <xml>
>     <id>id</id>
>     <listOfObjects>
>        <someobject>
>           <some>2</some>
>           <something>df</something>
>        </someobject>
>        <someobject>
>           <some>e</some>
>           <something>ef</something>
>        </someobject>
>     </listOfObjects>
> </xml>
>
> but class someobject in java:
> class someobject{
>     String id;
>     String some;
>     String something;
> }
>
> Is it possible to initialize id at class someobject with value from
> xml/value?

Not with the generalization your example implies. If you have a container object like:

Container {
        String id;
        someobject[] objects;
}

You can write a custom converter for the Container that also takes care of the objects. So the propagation of the id into the objects is your converter's responsibility.

If you want to refer your id from an arbitrary converter of someobject: No, not possible without bad hacks.

- Jörg
Reply | Threaded
Open this post in threaded view
|

RE: 1:N nodes

Jörg Schaible
In reply to this post by falcorn
Hi Piotr,

Piotr Idzikowski wrote on Wednesday, April 19, 2006 12:37 PM:

> Hi.
> I wondering if something like this is possible:
> i have xml:
> <xml>
>     <id>id</id>
>     <listOfObjects>
>        <someobject>
>           <some>2</some>
>           <something>df</something>
>        </someobject>
>        <someobject>
>           <some>e</some>
>           <something>ef</something>
>        </someobject>
>     </listOfObjects>
> </xml>
>
> but class someobject in java:
> class someobject{
>     String id;
>     String some;
>     String something;
> }
>
> Is it possible to initialize id at class someobject with value from
> xml/value?

It doesn't help to repeat the question, if you do not read the answers. Search the archive.

- Jörg
Reply | Threaded
Open this post in threaded view
|

RE: 1:N nodes

Jörg Schaible
In reply to this post by falcorn
Hi Piotr,

Piotr Idzikowski wrote on Friday, April 21, 2006 12:04 PM:

>> It doesn't help to repeat the question, if you do not read
> the answers. Search the archive.
>>
>> - Jörg
>>
> I haven't sent this question now. Look at the message date.
> It must be error of my mail server.
> Sorry.
> Greetings
> Piotr Idzikowski

OK, sorry myself. It just appeared again.

- Jörg
Reply | Threaded
Open this post in threaded view
|

Re: 1:N nodes

falcorn
In reply to this post by Jörg Schaible
>
>
> It doesn't help to repeat the question, if you do not read the answers. Search the archive.
>
> - Jörg
>
>
>
>  
I haven't sent this question now. Look at the message date.
It must be error of my mail server.
Sorry.
Greetings
Piotr Idzikowski

----------------------------------------------------------------------
Poznaj Stefana! Zmien komunikator! >>> http://link.interia.pl/f1924