My XML file has root
element and then many item
elements as root's children.
So it looks like this:
<root>
<item type=type1 id=1>...</item>
<item type=type1 id=2>...</item>
<item type=type2 id=3>...</item>
<item type=type3 id=4>...</item>
</root>
Every item
element has attribute that says what type of item we are dealing with.
In current XSD
xs:element name="root"
is as complexType which has sequnce of item
complexType.
I'm using JAXB to map my XML file to Java objects. Now I have to get all items and according to their types, create new, specific object. It get more and more complicated, as each item type has its own set of fields (child nodes). Is there any chance I can tell JAXB (by XSD) that there are different types of items
and according to item's name
attribute create object which I need? So for each item there should be separate complexType (which would be mapped to java object).
It would be all ok if my XML looked like this:
<root>
<item1 id=1>...</item1>
<item1 id=2>...</item1>
<item2 id=3>...</item2>
<item3 id=4>...</item3>
</root>