Ho trovato,questa classe per creare un file xml. Con un record di testa e tanti record successivi.
il,file dovrebbe essere così:
codice:<spettanze>ssss <elenco>hhss <altri tag> ...... .... </elenco> </spettanze>codice:privatevoid Crea(){ System.out.println("ok"); try { Element spettanze = new Element("spettanze"); Document doc = new Document(spettanze); doc.setRootElement(competenze); Element elenco = new Element("elenco"); Document doc1 = new Document(elenco); doc1.setRootElement(elenco); Element staff = new Element("elenco"); staff.setAttribute(new Attribute("prg", "1")); staff.addContent(new Element("cod").setText("11")); staff.addContent(new Element("Ufficio").setText("333")); staff.addContent(new Element("magazzino").setText("1717")) staff.addContent(new Element("mag1").setText("03")); // VARIABILE staff.addContent(new Element("codic").setText("AA")); // VARIABILE staff.addContent(new Element("inizio").setText("01/01/2015")); // VARIABILE staff.addContent(new Element("fine").setText("31/01/2015")); // VARIABILE staff.addContent(new Element("nomeEl").setText("Elencoa")); // VARIABILE doc.getRootElement().addContent(staff);> Element staff1 = new Element("staff"); staff1.setAttribute(new Attribute("id", "2")); staff1.addContent(new Element("firstname").setText("low")); staff1.addContent(new Element("lastname").setText("yin fong")); staff1.addContent(new Element("nickname").setText("fong fong")); staff1.addContent(new Element("salary").setText("188888")); doc.getRootElement().addContent(staff1); // new XMLOutputter().output(doc, System.out); XMLOutputter xmlOutput = new XMLOutputter(); // display nice nice xmlOutput.setFormat(Format.getPrettyFormat()); xmlOutput.output(doc, new FileWriter("c:\\file.xml")); System.out.println("File Saved!"); } catch (IOException io) { System.out.println("io.getMessage()"); }

Rispondi quotando