May 2015
Intermediate to advanced
234 pages
4h 18m
English
In this recipe, you'll learn to read an XML file as part of a read/process/write step.
We'll read this XML file:
<?xml version="1.0" encoding="UTF-8"?>
<records>
<person>
<firstName>Shania</firstName>
<age>49</age>
</person>
<person>
<firstName>Nelly</firstName>
<age>36</age>
</person>
</records>For each person's record in the XML file, a User object will be created. Make sure that the User class exists:
public class User {
private String firstName;
private int age;To parse the XML file, use StaxEventItemReader, which is provided by Spring Batch. To generate User objects, use XStreamMarshaller, a class from the Spring Object/XML Mapping project. Follow these steps:
Read now
Unlock full access