How to return the root element as a JAXB object from marshaled XML file

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) {
 } catch (FileNotFoundException e) {
 return object;


Popular posts from this blog

PrimeFaces Push with Atmosphere

Adding MyBatis mapper files dynamically

Creating JSF/CDI Maven project on Eclipse