Java/JAXB: Unmarshall XML elements with same name but different attribute values to different class members
I am trying to parse XML that has several "Fields" elements to different class members according to one of their attributes. Here is the XML:
<Series>
<Fields type="SelectedFields" operation="SUM">
<Field name="Remaining" />
<Field name="Invested" />
</Field>
<Fields type="FirstSelectedFie开发者_StackOverflowlds" operation="SUM">
<Field name="Estimated" />
</Field>
</Series>
And here is the java class it should be mapped to:
public class APMSeries {
private List<Field> selectedFields;
private List<Field> firstSelectedFields;
}
Can anyone tell me how can I set the Fields element with attribute type="SelectedFields" to the selectedFields member and the Fields element with the attribute type="FirstSelectedFields" to the firstSelectedFields member?
public class APMSeries {
@XmlElementWrapper(name="SelectedFields")
private List<Field> selectedFields;
@XmlElementWrapper(name="FirstSelectedFields")
private List<Field> firstSelectedFields;
}
精彩评论