The code looks like this:
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
XMLEventWriter eventWriter = outputFactory
.createXMLEventWriter(new FileOutputStream("output.xml"));
XMLEventFactory eventFactory = XMLEventFactory.newInstance();
XMLEvent end = eventFactory.createDTD("\n");
XMLEvent tab = eventFactory.createDTD("\t");
StartDocument startDocument = eventFactory.createStartDocument(
"UTF-8", "1.0");
eventWriter.add(startDocument);
...
When I open the xml file, google chrome says "encoding error" at the first utf-8 character, and if I look the xml code, it looks like:
?xml version="1.0"?
there is no encoding part in it...
Do you have any ideas what could be the problem?
encoding="..."defaults to UTF-8. So no worry. You might however look whether there is a BOM character as first character of the file, this is a (generally deprecated) Unicode zero width space. You will need a tool for seeing it. You could try deleting beginning chars.