public JAXBElement processFile(File file){ Class clazz = SomePojo.class; JAXBElement jaxbElement = null; try { JAXBContext jaxbContext = JAXBContext.newInstance(clazz); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); jaxbElement = unmarshaller.unmarshal(new StreamSource(file), clazz); } catch (Exception e) { e.printStackTrace(); } return jaxbElement; }