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 35 36 37 38 39 40 41
|
avec les imports suivant :
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
// 1. Instantiate a TransformerFactory.
tFactory = javax.xml.transform.TransformerFactory.newInstance();
// 2. Use the TransformerFactory to process the stylesheet Source and generate a Transformer.
xslSource = new javax.xml.transform.stream.StreamSource("un/chemin/vers/ton/fichier/xsl");
// Load the stylesheet. If it's already compiled, Resin will just
// load the compiled class. More sophisticated application will
// cache the Templates object.
stylesheet = tFactory.newTemplates(xslSource);
// 3.Create a transformer. This could also be called from a
// cached Templates object. The Transformer should not be cached.
transformer = stylesheet.newTransformer();
// 5.The source is a file.
source = new javax.xml.transform.stream.StreamSource("un/chemin/vers/ton/fichier/XML");
// 6.The result is a String.
StringWriter tampon = new StringWriter();
PrintWriter fluxSortie = new PrintWriter(tampon);
result = new javax.xml.transform.stream.StreamResult(fluxSortie);
transformer.transform(source, result);
user_agents_list = tampon.toString() ;
fluxSortie.flush();
fluxSortie.close();
fluxSortie = null; |
Partager