在阅读列表EmployeeParamData
和EmployeeParam
我的XML
<HostedEmployee>
<employeeid>12345</employeeid>
<employeeage>26</employeeage>
<employeeParamData>
<employeeParam name="attribute1"/>
<employeeParam name="attribute2">attribute2_value</employeeParam>
<employeeParam name="attribute3">attribute3_value</employeeParam>
<employeeParam name="attribute4">attribute4_value</employeeParam>
<employeeParam name="attribute5"/>
</employeeParamData>
</HostedEmployee>
我的域类是:
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name="HostedEmployee")
public class HostedEmployee {
private String employeeId;
public String getEmployeeId() {
return employeeId;
}
@XmlElement
public void setEmployeeId(String employeeId) {
this.employeeId= employeeId;
}
}
和解组在这里完成
public static void main(String[] args) {
try {
File file = new File(".../jaxbtest.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(HostedEmployee.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
HostedEmployee hostedEmployee= (HostedEmployee) jaxbUnmarshaller.unmarshal(file);
System.out.println(hostedEmployee.getEventGuid());
} catch (JAXBException e) {
e.printStackTrace();
}
}