here is my code:
Element FICHADAS = new Element("FICHADAS");
Document doc = new Document(FICHADAS);
try{
Element fichada = new Element("fichada");
//Nº TERMINAL
fichada.addContent(new Element("N_Terminal").setText(props.getProperty("N_TERMINAL")));
//TARJETA
fichada.addContent(new Element("Tarjeta").setText(codOperario));
//FECHA
Date fechaFormatoFecha = new Date( );
fichada.addContent(new Element("Fecha").setText(formatoFecha.format(fechaFormatoFecha)));
//HORA
Date fechaFormatoHora = new Date( );
fichada.addContent(new Element("Hora").setText(formatoHora.format(fechaFormatoHora)));
//CAUSA
fichada.addContent(new Element("Causa").setText("2"));
doc.getRootElement().addContent(fichada);
XMLOutputter xmlOutput = new XMLOutputter();
xmlOutput.setFormat(Format.getPrettyFormat());
xmlOutput.output(doc, new FileWriter("fichadas.xml"));
} catch(IOException io){
}
I'm creating a new document each time that i execute the program and i only want to create it if isn't exists, if the document exists just add the content.