camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shekher awasthi <shekher.awas...@gmail.com>
Subject Re: Way to convert CSV to XML in declarative way
Date Fri, 22 Jul 2011 02:19:25 GMT
Thanks Christion  and Lukasz for the help.
i still have doubt about what Lukasz  has suggested, my concern is to avoid
the the use of CSVConverterBean java class which actually is mapping the
data being provided my camel csv unmarshal to the JaxB generated classes.

using JaxB is not a big concern and can switch to XStream but the big
challange is to avoid using the mappping class and use some configuration
file for mapping so that we can at later stage do mapping change without any
code change

2011/7/22 Ɓukasz Dywicki <luke@code-house.org>

> You can use camel-xstream which have default behaviors and will create file
> similar to Christion example. You simply do marshal().xstream() instead of
> JAXB. No annotations, no classes, only declarative model.
>
> Regards,
> Lukasz
>
> > How about creating a default xml out of the csv and then convert this to
> the custom xml using xslt.
> >
> > For example for this csv:
> >
> > Name, Age
> > Anne, 23
> > Jim, 45
> >
> > the default xml could look like this:
> >
> > <data>
> > <line><Name>Anne</Name><Age>23</Age></line>
> > <line><Name>Jim</Name><Age>45</Age></line>
> > </data>
> >
> > The xslt does not have to be compiled and can be created using some
> tooling.
> > We could add a marshaller for the default format to camel.
> >
> > Christian
> >
> >
> > Am 21.07.2011 18:31, schrieb shekher awasthi:
> >> Hi All,
> >>
> >> i am trying my hands on camel where i have to fetch some csv file from a
> >> file system and needs to convert it to xml format and place it on some
> other
> >> system
> >>
> >> i am using camel for this and here is my sample POC code
> >>
> >> *import org.apache.camel.CamelContext;
> >>
> >> import org.apache.camel.Exchange;
> >>
> >> import org.apache.camel.Message;
> >>
> >> import org.apache.camel.Processor;
> >>
> >> import org.apache.camel.builder.RouteBuilder;
> >>
> >> import org.apache.camel.impl.DefaultCamelContext;
> >> import com.poc.convertor.CSVConverterBean;
> >>
> >>   public class TestPOC {
> >>
> >>            public static void main(String args[]) throws Exception {
> >>            CamelContext context = new DefaultCamelContext();
> >>            context.addRoutes(new RouteBuilder() {
> >>
> >>                   public void configure() {
> >>
> >> from("file:data/csv?noop=true").unmarshal().csv().bean(new
> >>
> CSVConverterBean(),"processCSVInvoice").to("file:data/csvoutput?fileName=test.xml").marshal("jaxb");
> >>
> >>
> >>                   }
> >>
> >>               });
> >>                context.start();
> >>                Thread.sleep(1000);
> >>                context.stop();
> >>           }
> >>
> >> }*
> >>
> >> In this approach camel csv unmarshaller will covert the csv file in to
> java
> >> list List<List<String>>  i have written a java converter
> >> CSVConverterBeanwhich will iterate the list and set the values in the
> >> respective java
> >> objects being generated by jaxb 2.x , final object is being marshaled in
> to
> >> xml and file is being saved.
> >>
> >> Everything is being working properly with only one issue , if in future
> >> there arises any request to change mapping we need to do the
> modification in
> >> CSVConverterBean and than this java file needs to be recompiled and need
> to
> >> be redistributed which we want to avoid.
> >>
> >> my question is, Is there any way by which we can map the values from the
> >> java List being given by Camel to the respective java classes being
> >> generated by the JaxB so that the need to recompile java code can be
> >> avoided.
> >> Thanks in advance for the help
> >>
> >
> >
> > --
> > --
> > Christian Schneider
> > http://www.liquid-reality.de
> >
> > Open Source Architect
> > Talend Application Integration Division http://www.talend.com
> >
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message