Return-Path: X-Original-To: apmail-camel-users-archive@www.apache.org Delivered-To: apmail-camel-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 90B6861FE for ; Thu, 21 Jul 2011 16:42:22 +0000 (UTC) Received: (qmail 34166 invoked by uid 500); 21 Jul 2011 16:42:22 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 34045 invoked by uid 500); 21 Jul 2011 16:42:21 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 34031 invoked by uid 99); 21 Jul 2011 16:42:21 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Jul 2011 16:42:21 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [62.75.158.78] (HELO mail.liquid-reality.de) (62.75.158.78) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Jul 2011 16:42:13 +0000 Received: from [10.0.0.101] (HSI-KBW-46-223-138-180.hsi.kabel-badenwuerttemberg.de [46.223.138.180]) by mail.liquid-reality.de (Postfix) with ESMTP id B233155F0054 for ; Thu, 21 Jul 2011 16:41:53 +0000 (UTC) Message-ID: <4E2856EE.6010309@die-schneider.net> Date: Thu, 21 Jul 2011 18:42:22 +0200 From: Christian Schneider User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 To: users@camel.apache.org Subject: Re: Way to convert CSV to XML in declarative way References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org 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: Anne23 Jim45 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> 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