Attends, je croyais que tu voulais écrire le document XML que tu viens de construire. D'où sort ce "<a></a>" ?
Une String n'a rien à voir avec XML. Et pour écrire un Document, oui, il faut utiliser le Document en question.
Version imprimable
Bonjour,
En réalité mon fichier XML se trouve dans un String (pour etre plus juste, mon fichier XML était en binaire que j'ai traduit en String)
mnt avec votre méthode SAXBuilder().build(new StringReader(xmlText)), je le traduit en XML puis je l'enregistre
le problème c'est qu'un bonheur ne dure jamais trop longtemps !!
je ne sais pas si tu as une idée comment convertir un fichier XML en binaire
maintenant j'utilise ce code:
et je l'appelle avec cette méthodeCode:
1
2
3
4
5
6
7
8
9
10
11 public byte [] getFichier(String fichier) throws IOException { //URL resource = this.getClass().getResource("/ressource/"+fichier+".xml"); URL resource = this.getClass().getResource(fichier+".xml"); InputStream in = resource.openStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; for(int read; (read = in.read(buf)) != -1;) { out.write(buf, 0, read); } return out.toByteArray(); }
et ça marche tres bien,Citation:
getFichier(nomFichier);
mais si je veux spécifier le dossier dans lequel se trouve mon fichier XML, il y a une erreur !!
exple
dans tous les cas, je te suis infiniment reconnaissante pour ton précieux aideCode:getFichier("C:\\BDD\\"+nomFichier);
Avec cette ligneCitation:
et je l'appelle avec cette méthode
et ça marche tres bien,Code:
1
2 getFichier(nomFichier);
mais si je veux spécifier le dossier dans lequel se trouve mon fichier XML, il y a une erreur !!
exple
Code:
1
2 getFichier("C:\\BDD\\"+nomFichier);
Il lit ton fichier xml a partir du myPackage/xml/tonFichier.xml si ton programme (ton) appartient au package myPackage.xmCode:
1
2 URL resource = this.getClass().getResource(fichier+".xml");
Tu peux aller voir ce lien pour ton probleme
http://www.velocityreviews.com/forum...e-failure.html