Hi Xandrios,
Xandrios wrote:
> Hi guys,
>
> I'm starting out with xstream, trying to parse XML data based on a XSD
> into objects. This works well except for nested lists of choice
> elements. For example this XSD definition:
>
> <xs:sequence>
> <xs:choice>
> <xs:element ref="volvo"/>
> <xs:element ref="chevy"/>
> <xs:sequence>
> <xs:element ref="policeCar"/>
> <xs:element ref="officerName" minOccurs="0" maxOccurs="2"/>
> </xs:sequence>
> </xs:choice>
> </xs:sequence>
>
> In other words, this would be valid data:
>
> <volvo color="red" />
> <chevy color="blue" />
> <policeCar />
> <officerName>Smith</officerName>
> <officerName>Jones</officerName>
> <volvo color="green" />
>
> I was thinking to make a generic wrapper that contains volvo, chevy
> and policeCar...when added to a list with the @XStreamImplicit
> annotation I suspect this to work. However for each policeCar there
> might be officers. The only way i'd see this work is using a wrapper
> around the policeCar and list of Officers...but that would break the
> XSD since the wrapper name would be included in the XML. Or would
> there be a way to 'hide' the wrapper object?
>
> Is there any way to properly map this XSD to objects? Any tips or
> suggestions would be very welcome!
Depends what you want. Actually you can define an implicit List<Object> and
you'll get the proper objects in the read sequence. However, you seem to
express that you PoliceCar object owns up to two OfficerNames as members.
The problem is that the XSD expresses something else here, these names are
not part of the policeCar element, they simply follow. In that case I'd go
for a custom converter for the complete list that is able to write/read a
PoliceCar list item in the required sequence together with the OfficerNames.
Cheers,
Jörg
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email