11,568 questions
How to create a simple Model for Rest
Benjo
1
Reputation point
package mypackage.model;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import java.io.File;
public class Model {
private static Model instance;
private Employees employees;
private final String XML_PATH="data.xml";
public static Model getInstance(){
if(instance==null){
instance=new Model();
}
return instance;
}
private Model(){
JAXBContext jaxbContext = null;
try {
jaxbContext = JAXBContext.newInstance(Employees.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
employees = (Employees) jaxbUnmarshaller.unmarshal(new File(XML_PATH));
} catch (JAXBException e) {
e.printStackTrace();
}
}
public Employees getEmployees(){
return employees;
}
public void save(){
JAXBContext jaxbContext = null;
try {
jaxbContext = JAXBContext.newInstance(Employees.class);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.marshal(employees, new File(XML_PATH));
} catch (JAXBException e) {
e.printStackTrace();
}
}
}
And heer something for C#:
Developer technologies C#
Sign in to answer