I want to have the following XML
<doc>
<items>
<item />
<item />
<item />
</items>
<things>
<thing />
<thing />
<thing />
</things>
</doc>
The schema would be something like
<schema>
<element name="doc">
<complexType>
<all>
<element name="items" minOccurs="1">
<complexType>
<sequence>
<element name="item" minoccurs="0" maxoccurs="unbounded" />
</sequence>
</complexType>
</element>
<element name="things" minOccurs="1">
<complexType>
<sequence>
<element name="thing" minoccurs="0" maxoccurs="unbounded" />
</sequence>
</complexType>
</element>
</all>
/<complexType>
</element>
</schema>
Now with JAXB it creates a class called Doc which would have an Items type which has an Item. Therefor to add the first element I have to do this.
Doc doc = new Doc();
Items items = new Items();
items.getItem().add(new Item());
doc.setItems(items);
I would like to be able to do the following instead:
Doc doc = new Doc();
doc.getItems().add(new Item());
Or even better:
Doc doc = new Doc();
doc.addItem(new Item());
Anyway of doing this through JAXB bindings?
Per the comment by nsfyn55, there does not seem to be any way to do this with bindings.
However, if you were using JAXB annoations, you could do: