I have these two types of XMLs with no predefined schemas:
A
<root-a>
<a-item id="a1">
<name>Name of A1</name>
<a-item id="a11">
<name>Name of A11</name>
</a-item>
<a-item id="a12">
<name>Name of A12</name>
<a-item id="a121">
<name>Name of A121</name>
</a-item>
<a-item id="a122">
<name>Name of A122</name>
</a-item>
</a-item>
</a-item>
<a-item id="a2">
<name>Name of A2</name>
</a-item>
</root-a>
B
<root-b>
<b-item id="b1">
<name>Name of B1</name>
<b-item id="b11">
<name>Name of B11</name>
</b-item>
<!-- etc., similar to A -->
</b-item>
</root-b>
The items can be nested to an arbitrary depth. The structure is the same, but the name of the root element and of the item elements is different. How can I map it to a single Java class structure, eg. like this one (getters and setters omitted) using JAXB:
public class Root {
private List<Item> items;
}
public class Item {
private String id;
private String name;
private List<Item> items;
}
I can map just one of the XML structures using JAXB annotations, but I don't know how to do it to accommodate both XMLs at the same time. I could create a parallel hierarchy for A and B with a common interface, but I hope there's a neater solution.