0

I have aspring batch job that use an StaxeventItemWriter , it's works fine . I want the result Xml file to be formatted , how can I do that . is there any property like ? this is my ItemWriter , I put only the relevant part of my code to simplify , if needed I can add the hole job.thanks

<bean id="xmlWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter">
       <property name="resource" value="file:src/main/resources/myFile.xml"></property>
       <property name="rootTagName" value="Users"></property><bean id="MyMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
  <property name="classesToBeBound">
    <list>
       <value>model.myModel</value>
    </list>
  </property>
</bean>
       <property name="marshaller" ref="MyMarshaller"></property>

    </bean> 

<bean id="MyMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
      <property name="classesToBeBound">
        <list>
           <value>model.myModel</value>
        </list>
      </property>
    </bean>
Omar B.
  • 441
  • 11
  • 39
  • Since you'r writer is StAX based, check this https://stackoverflow.com/questions/290326/stax-xml-formatting-in-java – Victor Gubin Jan 22 '19 at 14:00

1 Answers1

0

You can activate the JAXB_FORMATTED_OUTPUT option on the marshaller with:

<bean id="MyMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
  <property name="classesToBeBound">
    <list>
       <value>model.myModel</value>
    </list>
  </property>
  <property name="marshallerProperties">
    <map>
        <entry>
            <key>
                <util:constant static-field="javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT" />
            </key>
            <value type="java.lang.Boolean">true</value>
        </entry>
    </map>
  </property>
</bean>
Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50