Parsing XML with object reference creation



I'm parsing xml file and trying to create model from it. I'm using Simple XML library. My xml looks like this:



<?xml version="1.0" encoding="utf-8"?>
<root cycles_count="2">
<shifts>
<shift id="0" name="first"/>
<shift id="1" name="second"/>
<shift id="2" name="third"/>
<shift id="3" name="fourth"/>
</shifts>
<cycles>
<cycle name="A" start_date="1334620800000">
<cycle_shift id="0" />
<cycle_shift id="0" />
<cycle_shift id="1" />
</cycle>

<cycle name="B" start_date="1334620800000">
<cycle_shift id="1" />
<cycle_shift id="1" />
<cycle_shift id="2" />
</cycle>
</cycles>
</root>


Is there any way how to create object reference from cycle_shift to shift based on the same id? I want to achieve something like this (simplified version):



@Root
public class Shift {

@Attribute
int id;

@Attribute
String name;
}

@Root
public class Cycle {

@ElementList
List<Shift> shifts; // shifts connected by id's
}


Change of xml schema is possible too. Thanks in advance.


No comments:

Post a Comment