@@ -51,6 +51,15 @@ public enum Feature implements FormatFeature
5151         */ 
5252        WRITE_XML_DECLARATION (false ),
5353
54+         /** 
55+          * Feature that controls whether XML declaration should include the standalone attribute 
56+          * when generator is initialized (true) or not (false). Only honored when 
57+          * {@link Feature#WRITE_XML_DECLARATION WRITE_XML_DECLARATION} is enabled 
58+          * 
59+          * @since 2.19 
60+          */ 
61+         WRITE_STANDALONE_YES_TO_XML_DECLARATION (false ),
62+ 
5463        /** 
5564         * Feature that controls whether output should be done as XML 1.1; if so, 
5665         * certain aspects may differ from default (1.0) processing: for example, 
@@ -297,15 +306,24 @@ public void initGenerator()  throws IOException
297306        _initialized  = true ;
298307        try  {
299308            boolean  xmlDeclWritten ;
300-             if  (Feature .WRITE_XML_1_1 .enabledIn (_formatFeatures )) {
301-                 _xmlWriter .writeStartDocument ("UTF-8" , "1.1" );
302-                 xmlDeclWritten  = true ;
303-             } else  if  (Feature .WRITE_XML_DECLARATION .enabledIn (_formatFeatures )) {
304-                 _xmlWriter .writeStartDocument ("UTF-8" , "1.0" );
309+ 
310+             if (Feature .WRITE_XML_1_1 .enabledIn (_formatFeatures ) ||
311+                     Feature .WRITE_XML_DECLARATION .enabledIn (_formatFeatures )) {
312+ 
313+                 String  xmlVersion  = Feature .WRITE_XML_1_1 .enabledIn (_formatFeatures ) ? "1.1"  : "1.0" ;
314+                 String  encoding  = "UTF-8" ;
315+ 
316+                 if (Feature .WRITE_STANDALONE_YES_TO_XML_DECLARATION .enabledIn (_formatFeatures )) {
317+                     _xmlWriter .writeStartDocument (xmlVersion , encoding , true );
318+                 }else {
319+                     _xmlWriter .writeStartDocument (encoding , xmlVersion );
320+                 }
321+ 
305322                xmlDeclWritten  = true ;
306323            } else  {
307324                xmlDeclWritten  = false ;
308325            }
326+ 
309327            // as per [dataformat-xml#172], try adding indentation 
310328            if  (xmlDeclWritten  && (_xmlPrettyPrinter  != null )) {
311329                // ... but only if it is likely to succeed: 
0 commit comments