【发布时间】:2011-02-25 23:33:13
【问题描述】:
我正在使用 StAX 创建 XML 文件,然后使用 XSD 验证文件。
创建 XML 文件时出现错误:
javax.xml.stream.XMLStreamException: Underlying stream encoding 'Cp1252' and input paramter for writeStartDocument() method 'UTF-8' do not match.
at com.sun.xml.internal.stream.writers.XMLStreamWriterImpl.writeStartDocument(XMLStreamWriterImpl.java:1182)
这里是sn-p的代码:
XMLOutputFactory xof = XMLOutputFactory.newInstance();
try{
XMLStreamWriter xtw = xof.createXMLStreamWriter(new FileWriter(fileName));
xtw.writeStartDocument("UTF-8","1.0");} catch(XMLStreamException e) {
e.printStackTrace();
} catch(IOException ie) {
ie.printStackTrace();
}
我在 Unix 上运行此代码。有人知道如何设置版本和编码样式吗?
【问题讨论】: