first time using stack overflow, I'm now a student doing a project for analtics purpose, but the company store all the records into XML and I have to convert it and make a program as so to make it automated report send by email.
I'm using java to do XML parser and I'm now trying Apache common digester as other parser needs XSLT to do that, but iIwant a program that doesn't depends on XSLT because the company wants a system and sends a report like every 5 min of summary. So using XSLT may be quite slow as I saw some of the answer here. So may I know how to do that using digester or other methord, try to show some example the codes if possible, to make a conversion.
Here is the sample code I have build under digester:
public void run() throws IOException, SAXException {
Digester digester = new Digester();
// This method pushes this (SampleDigester) class to the Digesters
// object stack making its methods available to processing rules.
digester.push(this);
// This set of rules calls the addDataSource method and passes
// in five parameters to the method.
digester.addCallMethod("datasources/datasource", "addDataSource", 5);
digester.addCallParam("datasources/datasource/name", 0);
digester.addCallParam("datasources/datasource/driver", 1);
digester.addCallParam("datasources/datasource/url", 2);
digester.addCallParam("datasources/datasource/username", 3);
digester.addCallParam("datasources/datasource/password", 4);
File file = new File("C:\\Users\\1206432E\\Desktop\\datasource.xml");
// This method starts the parsing of the document.
//digester.parse("file:\\Users\\1206432E\\Desktop\\datasource.xml");
digester.parse(file);
}
Another one which is build using DOM to convert CSV to XML but still relies one XSLT file:
public static void main(String args[]) throws Exception {
File stylesheet = new File("C:\\Users\\1206432E\\Desktop\\Style.xsl");
File xmlSource = new File("C:\\Users\\1206432E\\Desktop\\data.xml");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(xmlSource);
StreamSource stylesource = new StreamSource(stylesheet);
Transformer transformer = TransformerFactory.newInstance()
.newTransformer(stylesource);
Source source = new DOMSource(document);
Result outputTarget = new StreamResult(
new File("C:\\Users\\1206432E\\Desktop\\temp.csv"));
transformer.transform(source, outputTarget);
}