Hi Jörg, thanks so much for your response. I was hoping to avoid writing custom converters but I'm starting to think I will need to indeed. Your example gave me another idea though:
If I can read all elements (volvo, chevy, policeCar and Officers) into one generic (ordered!) list (of type <Object>) I can simply post-process the list. When sequentially reading all entries I can match the officers to a policeCar. When I tried this in my project I found that the bindings are not that easy to accomplish this. The list (of type <Object>) does not get any elements added to it. So obviously xstream does not realize that it should expect these elements there and put them all into the generic list. The way I tried to fix this is to typecast the list as <Element> instead of <Object>. In the Element.class I then added the @XStreamInclude annotation to let xstream know all instances of volvo, chevy, policar and officer should be included. (these objects extend Element.class). Unfortunately this did not work either. Any tips on how to get the mapping for these elements right and put them into a generic <Object> list? Thanks! Xandrios On Mon, Feb 13, 2012 at 9:53 PM, Jörg Schaible <[email protected]> wrote: > 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 > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
