My recommendations:
1) I prefer using JAXB instead of XStream.
2) Modify your route so they looks like:
JaxbDataFormat jaxb = new JaxbDataFormat("com.mycompany...");
from("")
.unmarshall().csv()
.convertBodyTo(List.class) // see [1]
.marshal(jaxb)
.to("");
[1] http://camel.apache.org/type-converter.html
Best,
Christian
On Wed, May 16, 2012 at 9:55 PM, ambarish.d <[email protected]> wrote:
> Hello,
>
> I want to convert a CSV file to XML file in proper format. I have following
> code which is doing the Job but output is not a expected one.
>
> context.addRoutes(new RouteBuilder() {
> public void configure() {
>
> from("file://TEST?fileName=ArticleDistribution.csv").
> unmarshal().
> csv().
> marshal().
> xstream().
>
> to("file://TESTOUT?fileName=ArticleDistribution.XML");
> }
> });
>
> For Example:
> My CSV File looks like this:
>
> Name, Age, Sex, Zip
> Edward, 22,M,33639
> Ema,27,F,30330
>
> Output of Above code is:
>
> <list>
> <java.util.Arrays_-ArrayList>
>
> <string>Name</string>
> <string>Age</string>
> <string>Sex</string>
> <string>Zip</string>
>
> </java.util.Arrays_-ArrayList>
> <java.util.Arrays_-ArrayList>
>
> <string>Edward</string>
> <string> 22</string>
> <string>M</string>
> <string>33639</string>
>
> </java.util.Arrays_-ArrayList>
> ..
> </List>
>
> But Output I want is
>
> <List>
> <data>
> <Name>Edward</Name>
> <Age>22</Age>
> <Sex>M</Sex>
> <Zip>33639</Zip>
> </data>
> <data>
> ....
> </data>
> </List>
>
> Can anybody please help me and show the proper way of doing this. It will
> be
> a great help.
>
> thanks
> Amby
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Converting-CSV-to-XML-tp5711086.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>