I want to convert multiple xml object to csv object in apache camel. But I am just able to convert single object. With reference to below and attached code, I have tried some method sI have xml file like this
<company>
<employee>
<empId>1</empId>
<empName>peter</empName>
<sal>56000</sal>
</employee>
<employee>
<empId>2</empId>
<empName>mary</empName>
<sal>96000</sal>
</employee>
<employee>
<empId>3</empId>
<empName>alex</empName>
<sal>96000</sal>
</employee>
and want to convert it to csv. But I only manage to convert one data But i have no clue how to change the whole set
@Override
public void configure() throws Exception {
// Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
JaxbDataFormat xmlDataFormat = new JaxbDataFormat(); //1. XML Data Format
JAXBContext con = JAXBContext.newInstance(company.class);
xmlDataFormat.setContext(con);
DataFormat csv = new BindyCsvDataFormat(employee.class);
from("file:C:/inputFolder/.camel/xml?noop=true")
.unmarshal(xmlDataFormat)
.split(body(String.class).tokenize(","))
//Unmarshaled debug part
.process(new Processor(){
public void process(Exchange exchange) throws Exception {
//print string //
String myString = exchange.getIn().getBody(String.class);
System.out.println("unmarshalled output" + myString);
//print string//
//print array //
// Message msg =exchange.getIn() ;
// ArrayList<Employee> list = msg.getBody(ArrayList.class);
//list.forEach(emp -> System.out.println(emp));
//print array //
//// }}
}})
//Unmarshaled debug part
.marshal(csv)
.to("file:C:/outputFolder/csv").
// Marshalled output
process(new Processor(){
public void process(Exchange exchange) throws Exception {
//print string//
String myString = exchange.getIn().getBody(String.class);
System.out.println("marshalled output" + myString);
//print string//
//print array //
//Message msg =exchange.getIn() ;
// ArrayList<Employee> list = msg.getBody(ArrayList.class);
// list.forEach(emp -> System.out.println(emp));
//print array //
}})
;}
}