StAX XML formatting in Java

前端 未结 10 1412
-上瘾入骨i
-上瘾入骨i 2020-11-29 08:06

Is it possible using StAX (specifically woodstox) to format the output xml with newlines and tabs, i.e. in the form:


  
   someData
  &         


        
10条回答
  •  Happy的楠姐
    2020-11-29 08:50

    With Spring Batch this requires a subclass since this JIRA BATCH-1867

    public class IndentingStaxEventItemWriter extends StaxEventItemWriter {
    
      @Setter
      @Getter
      private boolean indenting = true;
    
      @Override
      protected XMLEventWriter createXmlEventWriter( XMLOutputFactory outputFactory, Writer writer) throws XMLStreamException {
        if ( isIndenting() ) {
          return new IndentingXMLEventWriter( super.createXmlEventWriter( outputFactory, writer ) );
        }
        else {
          return super.createXmlEventWriter( outputFactory, writer );
        }
      }
    
    }
    

    But this requires an additionnal dependency because Spring Batch does not include the code to indent the StAX output:

    
      net.java.dev.stax-utils
      stax-utils
      20070216
    
    

提交回复
热议问题