[英]The XML output from the Spring Batch Jaxb2Marshaller - Marshaller.JAXB_FORMATTED_OUTPUT is not working, why?
[英]I could not generate the formatted XML using Jaxb2Marshaller
根據Spring Batch文檔,Spring Batch可以生成格式化的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)支持格式化的XML。
但是默認情況下,Spring Batch不使用com.sun.xml.bind.v2.runtime.output.IndentingUTF8XmlOutput來生成輸出XML。
因此,我們需要創建一個StreamResult,以允許Spring Batch使用com.sun.xml.bind.v2.runtime.output.IndentingUTF8XmlOutput生成格式化的XML。
我假設您希望xml閱讀自己。 我不知道Spring批處理,但是您可以使用Notepad ++,下載XML工具插件,然后使用“ Pretty print(僅XML-帶換行符)”。 這不是理想的方法,但是比單行的閱讀要好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.