title: convert XML to CSV without XSLT in java
body: <p>first time using stack overflow, I'm now a student doing a project for analtics purpose, but the company store all the records into <strong>XML</strong> and I have to convert it and make a program as so to make it automated report send by email. </p>
  
  <p>I'm using java to do <strong>XML</strong> parser and I'm now trying <strong>Apache</strong> common digester as other parser needs <strong>XSLT</strong> to do that, but iIwant a program that doesn't depends on <strong>XSLT</strong> because the company wants a system and sends a report like every 5 min of summary. So using <strong>XSLT</strong> 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.</p>
  
  <p>Here is the sample code I have build under digester:</p>
  
  <pre><code>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);
  
  
    }
  </code></pre>
  
  <p>Another one which is build using <strong>DOM</strong> to convert <strong>CSV</strong> to XML but still relies one <strong>XSLT</strong> file:</p>
  
  <pre><code>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);
  }
  </code></pre>