This is the first time I've had to create an xml file using
java, so I hope that this is something obvious that I'm missing. I'm creating an xml file using org.w3c.dom.Document and I'm writing the xml document to the file system using javax.xml.transform.TransformerFactory. I'd like to include an xml stylsheet in the xml document, but I'm not sure how to do that. I think I'm looking for something like this: <?xml-stylesheet type="text/xsl" href="./css/myStyle.xsl"?>
My code looks something like this (thanks in advance):
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = null;
try {
db = dbf.newDocumentBuilder();
}
catch (ParserConfigurationException pce) {
System.err.println(pce);
}
Document
doc = db.newDocument();
Element root = doc.createElement("submission");
root.setAttribute("date", getTodaysDate(true));
doc.appendChild(root);
(build more xml here...)
File file = new File("myFile.xml");
Result result = new StreamResult(new FileOutputStream(file.toString()));
Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
xformer.transform(source, result);