Bonjour à tous !

Je vous expose mon problème. Mon programme Java génère un fichier XML grâce à la librairie Simple. J'ai confectionné un fichier XSL le formattant pour modifier sa structure. Lorsque je le formatte sur Altova XMLSpy, par exemple, il n'y a aucun souci. L'output est 100% correcte. Maintenant, j'ai dû l'intégrer dans mon programme.

Voici ma méthode qui "foire" :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 public void transform(File xmlIn, File xsl, File xmlOut) {
        try {
            SAXParserFactory spf = SAXParserFactory.newInstance();
            spf.setNamespaceAware(true);
            XMLReader reader = spf.newSAXParser().getXMLReader();
            // Création des filtres à appliquer au reader
            SAXTransformerFactory stf = (SAXTransformerFactory) TransformerFactory.newInstance();
            XMLFilter filtre1 = stf.newXMLFilter(new StreamSource(xsl));
            // On "lie" le reader aux filtres
            filtre1.setParent(reader);
            // Création de la source : c'est le dernier filtre de la chaîne
            // C'est lui qui indiquera au transformer quelles transformations à faire "avant"
            // Le résultat est le fichier HTML
            SAXSource source = new SAXSource(filtre1, new InputSource(new FileInputStream(xmlIn)));
            StreamResult resultat = new StreamResult(new FileOutputStream(xmlOut));
            //Transformation en chaîne
            Transformer transformer = stf.newTransformer();
            transformer.transform(source, resultat);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Sauvegarde.class.getName()).log(Level.SEVERE, null, ex);
        } catch (TransformerException ex) {
            Logger.getLogger(Sauvegarde.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ParserConfigurationException ex) {
            Logger.getLogger(Sauvegarde.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SAXException ex) {
            Logger.getLogger(Sauvegarde.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
Voici la méthode l'appelant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
public void transform() {
       save.transform(Constantes.xmlPath, Constantes.xslFirstPath, new File("musicXmlGenerated.xml"));
    }
Voici la classe Constantes :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public interface Constantes {
 
    public static final File xmlPath = new File("XMLJavaGenerated");
    public static final File xslFirstPath = new File("FormatXMLtoMusicXML.xsl");
    public static final String troisHuit = "3/8";
    public static final String sixHuit = "6/8";
    public static final String neufHuit = "9/8";
    public static final String quatreQuatre = "4/4";
    public static final String troisQuatre = "3/4";
    public static final String deuxQuatre = "2/4";
    public static final String silenceNote = "r4";
    public static final String noirNote = "c4";
    public static final String noteHead = "x";
    public static final String key = "0 major";
    public static final String clef = "percussion 2";
}
Je tiens à préciser que les fichiers XML et XSL se trouvent directement à la racine du projet.