使用XMLEventWriter设置独立='YES' [英] Setting standalone = 'YES' using XMLEventWriter
问题描述
我正在使用'XMLEventWriter'来生成Java中的XML文件.代码段如下:
I'm using 'XMLEventWriter' to generate an XML file in Java. Code snippet is as below:
XMLEventWriter writer = outputFactory.createXMLEventWriter(new FileWriter(outFile));
XMLEvent startEvent = eventFactory.createStartDocument("UTF-8","1.0",true);
writer.add(startEvent);
尽管将第三个参数设置为"true",但我看到生成的XML文档的标头没有独立的="YES"
In spite of setting the third argument to 'true', I'm seeing that the generated XML document's header does not have standalone="YES"
有人可以建议要进行更改(如果有)以使standalone ="yes"出现在生成的XML文件的文档标头中吗?
Could anyone suggest the changes (if any) to be made to make standalone="yes" appear in the generated XML file's document header ?
推荐答案
I was looking at the same issue (cf. java StAX - standalone property of StartDocument) and I found that is is unimplemented in my Java version:
软件包:com.sun.xml.internal.stream.writers
类XMLEventWriterImpl
public void add(javax.xml.stream.events.XMLEvent xMLEvent) {
//...
case XMLEvent.START_DOCUMENT :{
//...
StreamWriter.writeStartDocument(startDocument.getCharacterEncodingScheme(), startDocument.getVersion());
(请注意,此处未使用独立属性)
(note that standalone property is not used here)
然后在下一次通话中(类XMLStreamWriterImpl
)
Then in next call (class XMLStreamWriterImpl
)
public void writeStartDocument(String encoding, String version)
throws XMLStreamException {
//Revisit : What about standalone ?
//...
这是代码中的原始注释,因此除非使用Java实现,否则尚不受支持.
This is the original comment in the code, so it is unsupported yet unless implemented in Java.
我当前的Java版本是:
My current java version is:
java version "1.7.0_79"
OpenJDK Runtime Environment (IcedTea 2.5.5) (7u79-2.5.5-0ubuntu0.14.04.2)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)
java version "1.7.0_79"
OpenJDK Runtime Environment (IcedTea 2.5.5) (7u79-2.5.5-0ubuntu0.14.04.2)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)
也许它已在更高版本中修复?
Maybe it has been fixed in a later version ?
编辑
经过测试
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
问题仍然存在.
这篇关于使用XMLEventWriter设置独立='YES'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!