我使用这样的代码创建 xml:
public static void main(String[] args) {
XMLOutputFactory factory = XMLOutputFactory.newInstance();
XMLEventFactory eventFactory = XMLEventFactory.newInstance();
try {
XMLEventWriter writer =
factory.createXMLEventWriter(System.out);
XMLEvent event = eventFactory.createStartDocument("utf-8");
writer.add(event);
event = eventFactory.createStartElement(
"", "", "test");
writer.add(event);
event = eventFactory.createEndElement(
"", "", "test");
writer.add(event);
writer.flush();
writer.close();
} catch (XMLStreamException e) {
e.printStackTrace();
}
}
但是在标头属性编码中丢失了。怎么了?