Java, es4, lettura da file xml di dati da importare in ArrayOfAddresses
-
-
Definizione di una istanza dell'oggetto ArrayOfAddresses e lettura di file Xml tramite unmarshalling.
// 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");
}
-
Esempio di esportazione su file di un oggetto Document.
// 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");