One Star

Using CMap

Hi, I have input structure which is an XML and output structure which is CSV. I am using CMAP. Now I have done all the input to output mapping. The output CSV is generated. I have used simple loop to create CSV from XML input. However the additional requirement now is that the output CSV should only be created if some attributes in input XML have certain values else no output should be generated. How do I do this?
Thanks,
Prasad
3 REPLIES
Employee

Re: Using CMap

keep in mind that cMap is just one tool in the toolbox.  You also have the rest of the Camel components.  In your case I would suggest extracting the relevant input attributes using xPath and then using a conditional component like a content based router.  so your route might look like
cFile ---> cSetHeader ---> cContentBasedRouter --- (if XML attributes set) ---> cMap
                                                                    |
                                                                    |
                                                                    ----- (default) ---------------> other processing
One Star

Re: Using CMap

Understand. Let me try that. Thanks very much.
One Star

Re: Using CMap

Ok here is the problem I am having. My input XML structure is as follows -
<Root>
<Alloc Acct="acc1"  id="1"/>
<Alloc Acct="acc2" id="2" />
<Alloc Acct="acc3" id="3"/>
<Alloc Acct="acc4" id="4"/>
</Root>
Now my output CSV should include
acc3,3
acc4,4
So basically from the input XML can contain multiple <Alloc> tags and I want the output CSV to be generated if input XML contains either id="3" or id="4". Depending on what you get in incoming XML your output could be none if there are no 3 or 4 id attribute, or it could be CSV with one row if input contained id="3" or id = "4" or output could be CSV with both the ids if input contained 3 and 4 both. Hope it is clear
Now the problem I have is, if I use content based filtering then the whole XML with id ="1" and "2" is sent to CMAP as it passes the criteria that it contains "3" OR "4". Essentially I want the output CSV to only contain 3 and/or 4 irrespective of any other ids in input