StAX - Setting the version and encoding using XMLStreamWriter
Posted
by Anurag
on Stack Overflow
See other posts from Stack Overflow
or by Anurag
Published on 2010-05-31T12:45:51Z
Indexed on
2010/05/31
12:53 UTC
Read the original article
Hit count: 787
Hi, 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.
© Stack Overflow or respective owner