Re: [Simple-support] Deserialize with cycle strategy - parent reference as XML attribute?
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2008-05-07 18:03:25
|
Hi, The reason you are getting the null for the 'id' attribute is because the CycleStrategy removes the 'id' attributes from the XML element. If you want to keep them you would have to refactor or extend the CycleStrategy yourself. Or implement your own. Niall --- Timo Rumland <cr...@ol...> wrote: > Hello, > > I would like to build an XML file with this > framework for a simple > tree, where every node has a list of children and a > reference to it's > parent, basically no big deal. > > Now, I read the example on the tutorial page about > the cycle strategy. > There, the parent reference is always an XML > element, like this: > > > <child id="2" name="tom"> > <parent ref="1"/> > </child> > > > So the parent of the child with id 2 is an object > with id 1. > > What I want to know is, is it possible to have the > parent reference as > an attribute like this: > > > <node id="1" name="The father"> > <node id="2" name="The son" parent="1"> > </node> > > > Here, the node with id 1 is the parent of the > nodewith id 2. This is > denoted by the parent attribute. That attribute is > not required, as > can be seen from the node with id 1, which has no > parent attribute. > > I tried to deserialize is with a > > "Strategy strategy = new CycleStrategy( "id", > "parent" );" > > and got this error message: > > Exception in thread "main" > org.simpleframework.xml.load.AttributeException: > Value for > @org.simpleframework.xml.Attribute(name=, empty=, > required=true) on field 'id' is null > > > Is it possible to deserialize that XML? Or do I > always need to have a > parent references as XML Elements instead of > Attributes? > > > Thanks a lot for your help > > > Regards, > Timo > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by the 2008 > JavaOne(SM) Conference > Don't miss this year's exciting event. There's still > time to save $100. > Use priority code J8TL2D2. > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone > _______________________________________________ > Simple-support mailing list > Sim...@li... > https://lists.sourceforge.net/lists/listinfo/simple-support > ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ |