I want to read a xml file (like below) but I get an Execption. Could you please help me how can I fix this problem?
When you describing an XML model, you need to begin with a root entity (in your case it's the
element).
@XmlRootElement(name="config")
class Config implements Serializable {
private Log log;
private Env env;
@XmlElement(name="log")
public Log getLog() {
return this.log;
}
@XmlElement(name="env")
public Env getEnv() {
return this.env;
}
// Setters are omitted
}
And then you parse the XML like the following:
JAXBContext jaxbContext = JAXBContext.newInstance(Config.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Config config = (Config) jaxbUnmarshaller.unmarshal(file);
if (config != null && config.getLog() != null) {
customer = config.getLog().getProperties();
}