I am using StAX for creating XML files and then validating the file with and XSD.
I am getting an error while creating the XML file:
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)
Here is the code snippet:
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();
}
I am running this code on Unix. Does anybody know how to set the version and encoding style?