Bonjour à tous,
Je vous soumets un problème qui "m'agace" depuis hier matin.
J'ai un fichier xml que je veux transformer grace à xslt. Le problème c'est que lorsque j'applique la transformation avec java, tous les accents sont transformés en point d'interrogation. Je suppose que c'est à la lecture de ce fichier xml qu'il récupère n'importe quoi.
Pourtant je lui spécifie l'encodage à utiliser lors de la lecture du fichier et lors de la transformation.
De plus, ce phénomène ce produit seulement sur l'environnement linux. Quand j'execute mon java sue windows, cela ne se produit pas !!
Avez vous une idée de la cause de mon problème?
Voici le code que j'utilise, si ça peut vous aider :
String nomFichier = args[0]; // chemin du fichier xml bulletin
String nomPDF = args[1]; // chemin du fichier pdf a creer
String fichierXSL = args[2]; // chemin du fichier xslt a utiliser
File file = new File (nomFichier);
FileInputStream xmlFis = new FileInputStream(file);
InputStreamReader xmlIsr = new InputStreamReader(xmlFis,"iso-8859-1");
StreamSource sourceXML = new StreamSource(xmlIsr);
String targetFile = nomPDF;
String XSL = fichierXSL;
String contenuFO = getFo(sourceXML, XSL);
/* Fonction getFo */
public static String getFo(StreamSource fluxXml, String fichierXsl) {
String resultat = "PAS DE BULLETIN";
TransformerFactory transformerFactory = TransformerFactory.newInstance();
String resultat = "";
try {
StreamSource sourceXSL = new StreamSource(fichierXsl);
Transformer transformer = transformerFactory.newTransformer(sourceXSL);
transformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
transformer.transform(fluxXml,result);
resultat = writer.toString();
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return resultat;
}
Partager