public static Object getRootElement(String xmlpath, String package_names){
Object object = null;
try {
JAXBContext context = JAXBContext.newInstance(package_names);
File file = new File(xmlpath);
FileInputStream fileInputStream = new FileInputStream(file);
Unmarshaller unmarshaller = context.createUnmarshaller();
object = unmarshaller.unmarshal(file);
if (object instanceof javax.xml.bind.JAXBElement) {
javax.xml.bind.JAXBElement root = (javax.xml.bind.JAXBElement)object;
object = root.getValue();
}
} catch (JAXBException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return object;
}
Comments
Post a Comment