Listing 20-3. The contacts.xml File
<?xml version="1.0" encoding="UTF-8"?>
<contacts>
<contact>
<firstName>Kim Fung</firstName>
<lastName>Ho</lastName>
<birthDate>1980-07-30</birthDate>
<hobby>
<hobbyId>Swimming</hobbyId>
</hobby>
<hobby>
<hobbyId>Movies</hobbyId>
</hobby>
</contact>
</contacts>
In Listing 20-3, a contact's information is wrapped under the <contact> tag. The root tag is the
<contacts> tag, which can accommodate more contact information for import into the database.
We will use Castor to map the XML to the POJO. Listing 20-4 shows the mapping file
(/src/main/resources/oxm-mapping.xml).
Listing 20-4. Castor XML Mapping Definition File
<mapping>
<class name="com.apress.prospring3.ch20.domain.Contacts">
<field name="contacts" type="com.apress.prospring3.ch20.domain.Contact"
collection="arraylist">
<bind-xml name="contact"/>
</field>
</class>
<class name="com.apress.prospring3.ch20.domain.Contact" identity="id">
<map-to xml="contact" />
<field name="id" type="long">
<bind-xml name="id" node="element"/>
</field>
<field name="firstName" type="string">
<bind-xml name="firstName" node="element" />
</field>
<field name="lastName" type="string">
<bind-xml name="lastName" node="element" />
</field>
<field name="birthDate" type="string" handler="dateHandler">
<bind-xml name="birthDate" node="element" />
</field>
<field name="version" type="integer">
<bind-xml name="version" node="element" />
</field>
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home