I want to create an XML file from a comma delimited text file. I have a .txt file which contains some atomic values separated by commas. From this .txt file I want to create an XML file of those values. How do I do this ? Can I get the code also ?
Created May 7, 2012
Jan Matèrne Three possibilities:
You also can use Java, just read one line at a time. Then using a StringTokenizer to get one token at a time. Do the same thing Jan does in perl. Add a root, put each token into a child tag. It is simple and easy because your data is structured.
- convert the file manually
- write a generator which will do the convertion once
- use an adapter
print "<values> "; foreach (<STDIN>) { chomp; s/,/</value> <value>/g; print " <valuelist> <value>$_</value> </valuelist> "; } print "</values>";You can use that for starting. If you want write an adapter I recommend looking at chaperon (i never used it, but sounds good). Roseanne Zhang added:
You also can use Java, just read one line at a time. Then using a StringTokenizer to get one token at a time. Do the same thing Jan does in perl. Add a root, put each token into a child tag. It is simple and easy because your data is structured.