Сначала я написал для одного XML, который работает нормально. Теперь я пытаюсь конвертировать несколько файлов, которые выдают ошибку.Я поставил код для нескольких файлов.Ошибки, такие как незарегистрированное исключение ParserConfigurationException, SAXException;
import java.io.File;
import java.io.IOException;
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;
class Xml2Csv {
public static void main(String args[]) throws IOException {
// Path of folder where files are located
String folder_path = "C:\\Users\\SPARK\\Desktop\\javaf\\flir";
// creating new folder
File flir = new File(folder_path);
File[] file_array = flir.listFiles();
for (int i = 0; i < file_array.length; i++)
{
if (file_array[i].isFile())
{
//xsl stylesheet
File stylesheet = new File("C:\\Users\\SPARK\\Desktop\\javaf\\style.xsl");
File xmlSource = new File(folder_path + "\\" + file_array[i]);
String file_name = file_array[i].getName();
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(file_name + ".csv"));
transformer.transform(source, outputTarget);
}
}
}
}