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 ?

Jan Matèrne

Three possibilities:

  1. convert the file manually
  2. write a generator which will do the convertion once
  3. use an adapter
I did a quick hack in perl for the generator:
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.

Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact