Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Linux上使用javax.xml.transform.Transformer(但在windows上不使用)时出现CSV编码问题_Java_Xml_Linux_Transformer - Fatal编程技术网

在Linux上使用javax.xml.transform.Transformer(但在windows上不使用)时出现CSV编码问题

在Linux上使用javax.xml.transform.Transformer(但在windows上不使用)时出现CSV编码问题,java,xml,linux,transformer,Java,Xml,Linux,Transformer,我正在从XSL和XML文件生成一个CSV文件 两个原始文件都有作为标题 String csvPath = "myCsvPath"; String xmlPath = "xmlPath.xml"; String xslPath = "xslPath.xsl" File xmlFile = new File(xmlPath); File xslFile = new File(xslPath); Source xmlSource = new StreamSource(xmlFile); Sourc

我正在从XSL和XML文件生成一个CSV文件

两个原始文件都有
作为标题

String csvPath = "myCsvPath";
String xmlPath = "xmlPath.xml";
String xslPath = "xslPath.xsl"

File xmlFile = new File(xmlPath);
File xslFile = new File(xslPath);

Source xmlSource = new StreamSource(xmlFile);
Source xslSource = new StreamSource(xslFile);
Result result = new StreamResult(new ByteArrayOutputStream());

TransformerFactory transFac = new TransformerFactoryImpl();
Transformer trans = transFac.newTransformer(xslSource);
trans.setParameter("CSV_PATH","file:///" + csvPath);
trans.transform(xmlSource,result);
我使用net.sf.saxon.Controller作为转换器。 Saxon的版本是9.1.0.8,但我也尝试了9.4,但没有任何运气。 在我的XSL文件中,其中一个标签是“Disponibilité”

如果我在windows上的Dev tomcat上启动生成,CSV头是“Disponibilité”,没有问题。 但是,如果在linux虚拟机上启动生成,则“é”的编码不正确:“Disponibili
tèè½

我已经使用vim和log进行了检查,原始文件正确显示了“é”。 但是一旦生成完成,如果我通过vim或log解析文件的第一行,我会看到
é
被更改为

我检查了类似的问题,比如:

但是设置trans.setOutputProperty(OutputKeys.ENCODING,“UTF-8”)不工作。
使用StringWriter而不是ByteArrayOutputStream也是如此。

使用StringWriter时,如何检查结果?尝试打印
writer.toString().contains(“Disponibilit\u00e9”)
的值。另外,当您在Vim中查看原始文件时,
:set fileencoding
显示了什么?很抱歉,我想在收到消息后运行。所以我检查了writer的内容,但它实际上并不包含生成的内容。对于编码VIM,无论我是否尝试通过
setOutputProperty(OutputKeys.encoding,“ISO-8859-1”)对其他内容使用set编码,它总是
UTF-8
我刚刚用vim检查了
.xsl
&
.xml
文件的编码,即使这两个文件的头都是
.xml
文件显示了
UTF-8
编码和
.xsl
文件a
拉丁1
编码……那么,这似乎就是问题所在。我相信Vim,您可以执行以下操作:设置fileencoding=iso-8859-1
,然后保存文件,以强制以正确的编码保存文件。