[Simple-support] Deserialize with cycle strategy - parent reference as XML attribute?
Brought to you by:
niallg
|
From: Timo R. <cr...@ol...> - 2008-05-01 20:54:26
|
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
|