Java 变压器误差
我有一个做简单变换的对象。我创建了一个将XML数据转换为CSV的样式表。转换后,将创建一个CSV文件,但内容为空Java 变压器误差,java,xml,csv,Java,Xml,Csv,我有一个做简单变换的对象。我创建了一个将XML数据转换为CSV的样式表。转换后,将创建一个CSV文件,但内容为空 public class Simplex { private String xmlFile ; private String xslFile; private String outputFile; /** * Constructor for objects of class Simple */ public Simplex(String xmlFile, Stri
public class Simplex
{
private String xmlFile ;
private String xslFile;
private String outputFile;
/**
* Constructor for objects of class Simple
*/
public Simplex(String xmlFile, String xslFile,String outputFile)
{
this.xmlFile = xmlFile;
this.xslFile = xslFile;
this.outputFile= outputFile;
}
public String simplexTransform() throws
TransformerException,TransformerConfigurationException,FileNotFoundException,
IOException
{String mystring = "";
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new StreamSource(xslFile));
transformer.transform(new StreamSource(xmlFile), new StreamResult(new
FileOutputStream(outputFile)));
return mystring = "*Data Has Been Transformed,Check ouput File *";
}
}
这里没有足够的信息让我来帮助你。
xmlFile
和xslFile
的值是什么?如果它们不是URI,那么这就是您的问题。如果是,那么它们指向的文件的内容是什么?这些是我的输入C:\\thefiles\\Abbey.xml C:\\thefiles\\Abbeybe.csv C:\\thefiles\\Abbey\\CSVcon8.xslOk,很好,至少你正确使用了StreamSource构造函数(我犯了很多次这个错误)。Abbey.xml和CSVcon8.xsl的内容(或至少是结构)是什么。xml在每一行上都有for元素,而CSVcon8.xsl只是将xml转换为CSV。我目前的理论是,您的xsl可能没有正确设置以处理xml文件。如果您100%确信XML和XSL文件都是正确的,那么我可能无法帮助您。