Hello,

I want to generate a XML file with StaxEventItemWriter and XStreamMarshaller.

Expecting output is:

<records>
<date>8/3/2012</date>
<rec>
<collection>WOS </collection>
<originator_key>UT00001</originator_key>
<docid> DC0001</docid>
</rec>
<rec>
<collection>WOS </collection>
<originator_key>UT00002</originator_key>
<docid> DC0002</docid>
</rec>
<rec>
<collection>WOS </collection>
<originator_key>UT00003</originator_key>
<docid> DC0003</docid>
</rec>
<rec>
<collection>WOS </collection>
<originator_key>UT00003</originator_key>
<docid> DC0003</docid>
</rec>

</records>


Code :
XML configuration


<bean id="MetricFeedReader"
class="org.springframework.batch.item.database.Jdb cCursorItemReader"
scope="step">
<property name="dataSource" ref="jobRepository-dataSource" />
<property name="sql">
<value><![CDATA[select DOC_ID,COLLECTION_NAME,ARTICLE_ID from article]]></value>
</property>
<property name="rowMapper">
<bean id="employeeMapper" class="rowmapper.MetricFeedRowMapper" />
</property>
</bean>


<bean id="MetricFeedWriter" class="org.springframework.batch.item.xml.StaxEven tItemWriter">
<property name="resource" value="metricFeed.xml" />
<property name="marshaller" ref="MetricFeedMarshaller" />
<property name="rootTagName" value="alum_records" />
<property name="overwriteOutput" value="true" />
<property name="startElement" value="date"/>
</bean>



<bean id="MetricFeedMarshaller" class="org.springframework.oxm.xstream.XStreamMars haller">
<property name="aliases">
<util:map id="aliases">
<entry key="rec" value="command.MetricFeedContainer" />
</util:map>
</property>
</bean>

I am using POJO class to form a tag name


public class MetricFeed {


private String collectionId;
private long docId;
private String articleId;

public long getDocId() {
return docId;
}

public void setDocId(long docId) {
this.docId = docId;
}

public String getCollectionId() {
return collectionId;
}

public void setCollectionId(String collectionId) {
this.collectionId = collectionId;
}

public String getArticleId() {
return articleId;
}

public void setArticleId(String articleId) {
this.articleId = articleId;
}

}


I am using rowMapper to map the values and getting below output
public Object mapRow(ResultSet resultSet, int arg1) throws SQLException {

if(resultSet == null) {
return null;
}

MetricFeed metricFeed = new MetricFeed();
metricFeed.setCollectionId(resultSet.getString("CO LLECTION_NAME"));
metricFeed.setDocId(resultSet.getLong("DOC_ID"));
metricFeed.setArticleId(resultSet.getString("ARTIC LE_ID"));
return metricFeed;


<records>
<rec>
<collection>WOS </collection>
<originator_key>UT00001</originator_key>
<docid> DC0001</docid>
</rec>
<rec>
<collection>WOS </collection>
<originator_key>UT00002</originator_key>
<docid> DC0002</docid>
</rec>
<rec>
<collection>WOS </collection>
<originator_key>UT00003</originator_key>
<docid> DC0003</docid>
</rec>
<rec>
<collection>WOS </collection>
<originator_key>UT00003</originator_key>
<docid> DC0003</docid>
</rec>

</records> like this. I don't know how to add date tag for a single time in this xml.