[英]I could not generate the formatted XML using Jaxb2Marshaller
According to the Spring Batch document, Spring Batch could generate the formatted xml file, but I failed, all XML elements are generated in one line. 根据Spring Batch文档,Spring Batch可以生成格式化的xml文件,但是我失败了,所有XML元素都在一行中生成。
Test steps 测试步骤
Before running the job, I make below changes on /spring-batch-2.1.9.RELEASE-no-dependencies/spring-batch-2.1.9.RELEASE/spring-batch-samples/src/main/resources/jobs/iosample/xml.xml 在运行作业之前,我对/spring-batch-2.1.9.RELEASE-no-dependencies/spring-batch-2.1.9.RELEASE/spring-batch-samples/src/main/resources/jobs/iosample进行以下更改/xml.xml
<bean id="itemWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter">
<property name="resource" ref="outputResource" />
<property name="marshaller" ref="customerCreditMarshaller2" />
<property name="rootTagName" value="customers" />
<property name="overwriteOutput" value="true" />
</bean>
<bean id="customerCreditMarshaller2" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPaths">
<list>
<value>com.test.domain</value><!-- the package is generated from a XSD -->
</list>
</property>
<property name="marshallerProperties">
<map>
<entry key="jaxb.formatted.output"><value type="java.lang.Boolean">true</value></entry>
</map>
</property>
JAXB API (com.sun.xml.bind.v2.runtime.output.IndentingUTF8XmlOutput) supports the formatted XML. JAXB API(com.sun.xml.bind.v2.runtime.output.IndentingUTF8XmlOutput)支持格式化的XML。
But by default, Spring Batch does not use com.sun.xml.bind.v2.runtime.output.IndentingUTF8XmlOutput to generate the output XML. 但是默认情况下,Spring Batch不使用com.sun.xml.bind.v2.runtime.output.IndentingUTF8XmlOutput来生成输出XML。
So we need to create a StreamResult to let Spring Batch use com.sun.xml.bind.v2.runtime.output.IndentingUTF8XmlOutput to generate the formatted XML. 因此,我们需要创建一个StreamResult,以允许Spring Batch使用com.sun.xml.bind.v2.runtime.output.IndentingUTF8XmlOutput生成格式化的XML。
I'm assuming you want the xml to read yourself. 我假设您希望xml阅读自己。 I don't know about spring batch, but you could use Notepad++, download the XML tools plugin, then use "Pretty print (XML only - with line breaks)".
我不知道Spring批处理,但是您可以使用Notepad ++,下载XML工具插件,然后使用“ Pretty print(仅XML-带换行符)”。 It's not ideal, but read better than all on one line.
这不是理想的方法,但是比单行的阅读要好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.