Hello,

J'avais un fichier xslt et je transformais un XML avec celui-ci. Tout allait bien.

J'ai voulu remplacer ce fichier xslt par une chaine de caractères, et là plus rien... Il me dit qu'il n'arrive pas à valider la feuille de style... Comment faire?

Mon code:
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
29
30
31
32
33
34
File file= new File(path + File.separator + xmlFile);
 
 
        String xslt = 
            "<?xml version=\"1.0\"?>"+
            "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:xalan=\"http://xml.apache.org/xslt\" version=\"1.0\">"+
            "  <xsl:output method=\"xml\" indent=\"yes\" xalan:indent-amount=\"3\" />"+
            "  <!-- copy out the xml -->"+
            "  <xsl:template match=\"* | @*\">"+
            "    <xsl:copy>"+
            "      <xsl:copy-of select=\"@*\" />"+
            "      <xsl:apply-templates />"+
            "    </xsl:copy>"+
            "  </xsl:template>"+
            "</xsl:stylesheet>";
 
        Source xmlSource = new StreamSource(file);
        Source xslSource = new StreamSource(xslt);
 
        StringWriter writer = new StringWriter();
        Result destResult = new StreamResult(writer);
 
        TransformerFactory transFact = TransformerFactory.newInstance();
 
        try{ 
            Transformer transFinal = transFact.newTransformer(xslSource);
            transFinal.transform(xmlSource, destResult);
            FileWriter fwriter = new FileWriter(file);
            fwriter.write(writer.toString());
            fwriter.close();
        }        
        catch(Exception e){
            throw new ConfigException("Unable to indent XML file! "+e.getMessage());
        }
Merci d'avance!!

A+