Android Simple XML Serializer - handling mixed types in XML

Good morning everyone,I have a question about http://simple.sourceforge.net/ serializer.I am using it in an android application to pull fields from XML and render them on the form. I do have control over the XML to a certain extent but it is based on an external structure so I'd rather not change it if I don't have to.My problem is this: One of the elements in my Field XML is Datatype, which instructs the device on which widget to render. I have two general categories of data types, simple (e.g. string or int) and complex (e.g. Integer Option (1 = high, 2 = medium, 3 = low), which will render a spinner or radio button).The structure for the two looks as follows:Simple\[code\]<field> ... <datatype> string </datatype> ...</field>\[/code\]Complex\[code\]<field> ...<datatype> <integer_option> <option> <number>1</number> <label>high</label> </option> <option>...</option> </integer_option></datatype></field>\[/code\]Now I can get each one working on its own easily enough, but I can't figure out how to make it decode into either depending on the XML.What I'm trying at the moment (which obviously isn't working or I wouldn't be here :P) is as follows:\[code\]class Field { @Element(required=false) private String Datatype; @ElementUnion({ @Element(name="boolean_option", type=BooleanOption.class, required=false), @Element(name="integer_option", type=IntegerOption.class, required=false), }) @Path("Datatype") private DatatypeComplex DatatypeComplex;}\[/code\]I would appreciate it if anyone could help me to find the problem with this code, or suggest an alternate way of doing this.ThanksBevan
 
Back
Top