我无法解组 xml,因为不明白如何在另一个对象中注释对象类。请帮忙。
XML:
<?xml version="1.0" encoding="UTF-8"?>
<ODZ xmlns="http://www.company.com/1.0" >
<Data DataID="ZZZ">
<UserData UserKey="user_001">
<UserEvent>...</UserEvent>
</UserData>
</Data>
</ODZ>
容器类:I. 第一级与第二级(ODZ -> Data)的链接。
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "ODZ", namespace = "http://www.company.com/1.0")
public class ODZContainer {
private ImportContainer importContainer;
@XmlElement (name = "Data", type=ImportContainer.class)
public ImportContainer getImportContainer() {
return importContainer;
}
}
二、第二级,链接到第三级(Data -> UserData)。
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "Data")
public class ImportContainer {
private String DataID;
private ArrayList<UserDataBean> userDataBean;
@XmlElement (name = "UserData", type=UserDataBean.class)
public ArrayList<UserDataBean> getUserDataBean() {
return userDataBean;
}
@XmlAttribute(name = "DataID")
public String getDataID() {
return DataID;
}
}
三、第三级链接到第四级(UserData-> UserEvent)。
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "UserData")
public class UserDataBean {
private ArrayList<UserEventBean> userEventData;
private String userEventID;
@XmlAttribute(name = "UserKey")
public String getUserEventID() {
return userEventID;
}
@XmlElement (name = "UserEvent", type=UserEventBean.class)
public ArrayList<UserEventBean> getUserEventBean() {
return userEventData;
}
}