Reputation: 347
I have a database Table with three columns: id, description and date, the id column is numeric, the description column is a string which contains an xml line and a date column. the description column is something like this :
<catalog_item >
<item_number>QWZ5671</item_number>
<price>39.95</price>
<size description="Medium">
<color_swatch image="red_cardigan.jpg">Red</color_swatch>
<color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch>
</size>
<size description="Large">
<color_swatch image="red_cardigan.jpg">Red</color_swatch>
<color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch>
</size>
</catalog_item>
<catalog_item >
<item_number>RRX9856</item_number>
<price>42.50</price>
<size description="Small">
<color_swatch image="red_cardigan.jpg">Red</color_swatch>
<color_swatch image="navy_cardigan.jpg">Navy</color_swatch>
<color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch>
</size>
<size description="Medium">
<color_swatch image="red_cardigan.jpg">Red</color_swatch>
<color_swatch image="navy_cardigan.jpg">Navy</color_swatch>
</size>
</catalog_item>
with multiple nested tags. All tags are written in the same record in the description column. I can write a select statement to read the record from the database , but in this case, i'll have a custom object which contains the whole row from the description column, is there a way to extract all these nodes of the xml line into separated java fields with spring batch.
Thks.
Upvotes: 1
Views: 114
Reputation: 2371
This is not really spring-batch's job to transform XML files into DTOs (or any java bean), you should use something like Jaxb (or any other XML mapping library).
As for spring-batch, you could call Jaxb in a FieldSetMapper (a component between the reader
and the processor
that maps objects).
Upvotes: 2