// unmarshalling File f1 = new File("prova.xml"); JAXBContext jaxbContext = JAXBContext.newInstance(ArrayOfAddresses.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); // Object objectJAXB = unmarshaller.unmarshal(f); //.unmarshal( new FileInputStream(filePath)); ArrayOfAddresses lista2 = (ArrayOfAddresses) unmarshaller.unmarshal(f); if (lista2 == null) { System.out.println("errore: lista non letta"); }
// salvataggio Document Source src= new DOMSource(doc1); File file = new File("provaDoc2.xml"); Result rs = new StreamResult(file); TransformerFactory tmf = TransformerFactory.newInstance(); Transformer trnsfrmr = tmf.newTransformer(); trnsfrmr.transform(src, rs); System.out.println("XML file is created successfully");