I need to parse XML with JAXB which describes structure. E.g. it can be something like:
<structure name="s1">
<integer value="15" name="i1" />
<structure name="s1_1">
<string value="hello" />
</structure>
</structure>
As you can see, structures can be nested. So my questions are:
- what is the best practices to represent such structure in Java
- how can it be parsed using JAXB?
UPD: Structure can contain several different items (integers, strings, float numbers, arrays/etc) and I can’t make assumption about it contents. I just know possible types of fields, but not their quantity or order.
How about:
Parsing with JAXB pretty much reduces to using the JAXB tools on the class above and generate the appropriate stubs/proxies/whatever and feed appropriate XML into the marshaller – there are plenty examples on SO and elsewhere.
Cheers,