- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 233
 
          Add feature to include standalone='yes' in xml declaration
          #745
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
  
    Add feature to include standalone='yes' in xml declaration
  
  #745
              Conversation
| 
           Please describe why you even need standalone='yes'. That flag is only supposed to used with DTDs - and hardly anyone uses DTDs any more.  | 
    
        
          
                src/main/java/com/fasterxml/jackson/dataformat/xml/ser/ToXmlGenerator.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/main/java/com/fasterxml/jackson/dataformat/xml/ser/ToXmlGenerator.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/test/java/com/fasterxml/jackson/dataformat/xml/ser/TestXmlDeclaration.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/test/java/com/fasterxml/jackson/dataformat/xml/ser/TestXmlDeclaration.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      
          
 First of all thank you so much for reviewing this so quickly. We work with a very nasty consumer on the other end which refuses to read the XML if standalone=yes is missing.  | 
    
ec29218    to
    633140f      
    Compare
  
    e95bf81    to
    a619e5c      
    Compare
  
    standalone='yes' in xml declarationstandalone='yes' in xml declaration
      
By default there is no easy way with Jackson XML to include
standalone='yes'inside the XML declaration. It requires swapping out thexmlWriterwhich is really cumbersome because the implementations ofBaseStreamWriterfrom Woodstox are final likeRepairingNsStreamWriter. Hence to change this the entirety of e.g.RepairingNsStreamWriterneeds to be copied to the project only to overrideBaseStreamWriter#writeStartDocumentto calldoWriteStartDocument(version, encoding, "yes");instead of the defaultdoWriteStartDocument(version, encoding, null);.This PR adds
ToXmlGenerator.Feature.WRITE_STANDALONE_YES_TO_XML_DECLARATIONwhich isfalseby default.When enabled
standalone='yes'will be added to the XML declaration if including it is enabled as well:will cause the first line to have
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>There is definetely a need for this as demonstrated by these posts: