Consider the below CSV file pattern:
 

IBM,70
ORCL,20
MSFT,11

This file contains one Stock Symbol, a delimiting comma, and a corresponding Stock Price on each line of the file. This represents a typical comma-seperated values (CSV) data file produced by many applications. This data needs to be transformed into a well-formed XML file, so that the data can be consumed by an external application. The desired result looks like this:  


	
		IBM
		70
	
	
		ORCL
		20
	
	
		MSFT
		11
	

Below is the FFD required to accomplish this task:
 



	
		
		
	

Let's examine the above FFD here:
 

This is the required root node of the FFD. The value of the name attribute becomes the root node of the resulting XML.

Here, the first grouping of data is declared. It may occur 0 to an infinite number of times in the file. Each group is delimited by the “\n” character combination (CRLF).
 

This is the first field of data in the group. Since it is first, it has no delimiter. Since neither the minOccurs nor maxOccurs attributes are explicitly set, both default to 1. One
instance of this data must exist in the group, and only one.

 

This is the next field of data. The list of Fields is synchronous; the data must occur in this order. In this case, the field is delimited by the comma character. Again, the data field must occur and only once in the data.

 

 

There are no other fields included in the group. The file may end here. If it does not, the processor will now look for the next delimiter declared in this FFD or a Literal. In this
case, the next delimiter is a CRLF (except for the last line), which indicates the beginning of another CSVLine group.


The root node is closed.

 


Below is an illustration of the stylesheet which can be used in IBM Websphere Datapower in the Binary Transformation action:
 



	
	
	
	
		
	


Enter your email address:

Delivered by FeedBurner



Sandeep Joshi
Mathematics, Technology and Programming are my passion. I am a part of Java Ecosystem and through this blog, I contribute to it. I am here to blog about my interests, views and experiences.
I am on Google+ and Facebook.
I feel proud to be listed as a "National Memory Record Holder" in the Limca Book of Records, 2009 and have attempted for an International Memory record in the Guiness Book of Records. I can remember the value of PI upto 10,000 digits after the decimal (3.1415.....). You can contact me on javagenious.com(At)gmal.com ; I would like to hear from you :)