Java Reference
In-Depth Information
rootElementAttributes
Map<String, String>
null
This key/value pairing is
appended to the root tag of
each fragment with the keys as
the attribute names and value
as their values.
rootTagName
String
null
(required)
Defines the root XML tag the
XML document.
saveState
boolean
true
Determines if Spring Batch
keeps track of the state of the
ItemWriter (number of items
written, and so on).
transactional
boolean
true
If true , the writing of the
output is delayed until the
transaction is committed, to
prevent rollback issues.
version
String
"1.0"
Version of XML the file is
written in.
To look at how StaxEventItemWriter works, let's update formatJob to output the customer output in
XML. Using the same input from the previous examples, Listing 9-18 shows the new output you create
when you update the job.
Listing 9-18. customer.xml
<?xml version="1.0" encoding="UTF-8"?>
<customers>
<customer>
<id>0</id>
<firstName>Richard</firstName>
<middleInitial>N</middleInitial>
<lastName>Darrow</lastName>
<address>5570 Isabella Ave</address>
<city>St. Louis</city>
<state>IL</state>
<zip>58540</zip>
</customer>
...
</customers>
In order to generate the output shown in Listing 9-18, you reuse the formatJob configuration but
replace flatFileOutputWriter with a new xmlOutputWriter that uses the StaxEventItemWriter
ItemWriter implementation. To configure the new ItemWriter, you provide three dependencies as
shown in Listing 9-19: a resource to write to, a reference to an org.springframework.oxm.Marshaller
implementation, and a root tag name ( customer in this case).
 
Search WWH ::




Custom Search