Sathish Rao
Sathish Rao

Reputation: 75

Setting standalone = 'YES' using XMLEventWriter

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);

In spite of setting the third argument to 'true', I'm seeing that the generated XML document's header does not have standalone="YES"

Could anyone suggest the changes (if any) to be made to make standalone="yes" appear in the generated XML file's document header ?

Upvotes: 3

Views: 2233

Answers (1)

csauvanet
csauvanet

Reputation: 554

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:

package: com.sun.xml.internal.stream.writers

class 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)

Then in next call (class XMLStreamWriterImpl)

public void writeStartDocument(String encoding, String version)
    throws XMLStreamException {
    //Revisit : What about standalone ?
    //...

This is the original comment in the code, so it is unsupported yet unless implemented in 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)

Maybe it has been fixed in a later version ?

EDIT

Just tested with

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)

and the issue still exists.

Upvotes: 2

Related Questions