代码如下所示:
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);
...
当我打开 xml 文件时,谷歌浏览器在第一个 utf-8 字符处显示“编码错误”,如果我查看 xml 代码,它看起来像:
?xml version="1.0"?
里面没有编码部分...
你有什么想法可能是什么问题?