0

I have managed to export a CSV file using JAVA. Now, I want those CSV files to be saved because I noticed that if I do not manually save them, I cannot use my CSV files to connect with other programs and do things with them. Please take a look, and help me out. Thank you !!! package edi.converter.main;

import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import org.w3c.dom.Document;

import edi.converter.outbound.sqlserver.OutboundProcess;

public class MainAppConverter {

    public static void main(String[] args) throws Exception {
        Result outputTarget = new StreamResult(new File("C:\\Users\\Khoa S Tran\\Desktop\\out.csv"));
        Result outputTarget1 = new StreamResult(new File("C:\\Users\\Khoa S Tran\\Desktop\\out1.csv"));
        File stylesheet = new File("C:\\Users\\Khoa S Tran\\Desktop\\style.xsl");
        File xmlSource = new File("C:\\Users\\Khoa S Tran\\Desktop\\data.xml");
        File xmlSource1 = new File("C:\\Users\\Khoa S Tran\\Desktop\\data1.xml");
        
        // it is noted that it is impossible/challlenging to combine xml files then export them to one csv
        //suggestion will be concatenate multiple csv files together
        
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.parse(xmlSource);
        Document document1 = builder.parse(xmlSource1);

        StreamSource stylesource = new StreamSource(stylesheet);
        Transformer transformer = TransformerFactory.newInstance().newTransformer(stylesource);
        Source source = new DOMSource(document);
        Source source1 = new DOMSource(document1);
        transformer.transform(source, outputTarget);
        //OutboundProcess.trytoExportSQL();
        transformer.transform(source1, outputTarget1);
    }

}

Bottom line is I have 2 XML files, I want to read them, combine them together, and export them to 1 single CSV file.

In case you might wonder where I can find the source code for concatenating 2 CSV's: How to merge multiple csv files into one in Java

SKT007
  • 1
  • can you please share your XSL file,..also what is the issue exactly? after you have called 'transformer.transform(source, outputTarget);' , is the output not written to file? – Abhinaba Chakraborty Jul 13 '20 at 07:44
  • Does this answer your question? [How can I merge XML files?](https://stackoverflow.com/questions/6045010/how-can-i-merge-xml-files) – smwhr Jul 13 '20 at 10:04
  • Well, my question is pretty simple. I want to merge 2 CSV files together. You can create random CSV files, but I cannot combine them together – SKT007 Jul 13 '20 at 13:43

0 Answers0