Unmarshalling generic child using Jaxb

jojee

New Member
I have an xml file in the format:-\[code\]<item> <item_attribute index="1" type="1" > <name>value1</name> </item_attribute> <item_attribute index="2" type="1" > <a_differnt_name>value2</a_different_name> </item_attribute> <item_attribute index="5" type="2" > <another_name>value3</another_name> </item_attribute></item>\[/code\]I am using JAXB to unmarshall the xml and have a class set up for each element other than the child of the 'item_attribute'. I want to generically unmarshall the data (element name and element value) within each 'item_attribute' element without knowing what the element is called.All I know is the 'item_attribute' always has only 1 child element and that child could be called and contain anything.I tried using: \[code\]public class Item_attribute { private int index; private Object data; @XmlAttribute(name = "index") public int getIndex() { return index; } public void setIndex(int index) { this.index = index; } @XmlAnyElement(lax = true) public Object getData() { return this.data; }}\[/code\]but it keeps throwing an illegalannotationexception!
 
Back
Top