append node to an xml in Java

HearthrobZ

New Member
I can't append correctly some info to my xml file. That's the scrivi function\[code\] public String scrivi (Document doc, File dest) { try { DOMSource sorgente = new DOMSource (doc); StreamResult sr = new StreamResult (dest); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transf = tf.newTransformer(); transf.transform (sorgente, sr); return "Tutto ok"; } catch (TransformerConfigurationException tce) { System.out.println(tce.getMessage()); return "<h1> Config </h1>"; } catch (TransformerException te) { System.out.println(te.getMessage()); return "<h1> Transformer Errore </h1>"; } }\[/code\]and tath is my code:\[code\] try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.parse(getClass().getResourceAsStream("/azioni.xml")); Element root = document.getDocumentElement(); Element new_azione = document.createElement("azione"); Element id = document.createElement("id_azione"); id.setTextContent(id_azione); Element nome = document.createElement("nome_azione"); nome.setTextContent(nome_azione); Element prezzo_a = document.createElement("prezzo"); prezzo_a.setTextContent(prezzo); new_azione.appendChild(id); new_azione.appendChild(nome); new_azione.appendChild(prezzo_a); document.getDocumentElement().appendChild(new_azione); String nomexmlOut="/azioni.xml"; File filedest = new File(nomexmlOut); out.println(this.scrivi(document, filedest));}\[/code\]I get the error Transformer Errore ... how can I solve? what's Wrong?* UPDATE *Error Info\[code\]java.io.FileNotFoundException: /azioni.xml (Permission denied)\[/code\]
 
Back
Top