Altova Mailing List Archives

Re: convert cobol to XML, have a supplied Schema

From: Peter Flynn <peter.nosp@-.--------.-->
Date: 4/16/2006 12:03:00 AM

mmitche4 wrote:
> We are a non-profit with few modern tools other than Win2000 server, XP, and 
> VBScript, etc.
> I can use Cobol to pull my demographic data off to a CSV or text file. I 
> then wish to
> convert it to XML. I have been given a Schema and XML examples, which I 
> understand, but know not how to start. I have a little VBScript experience. 
> This is for one data file only, and budget will not allow purchase of robust 
> tools.

Use the tools that come with Cygwin and you'll have access to awk
and a bunch of other useful stuff. I use TSV rather than CSV.

Here's an awk command to turn a TAB-separated file into XML (not 
comma-separated: this avoids any ambiguity with embedded commas, 
assuming none of your data actually contain a TAB character):

awk -F"	" 'BEGIN {print "<?xml version=\"1.0\"?>\n<doc>"}                   {print "  <record>";                   for(i=1;i<=NF;++i)print "    <field" i ">"                      gensub("(^\"|\"$)","","G",$i)                      "</field" i ">";                   print "  </record>"}             END {print "</doc>"}' myfile.tsv >myfile.xml


a    "this one"    3.14159    fred
b    "another long field with lots of text in it"    4    mike

(that is actually TAB-separated but the TABs may not make it through
the network to you)

<?xml version="1.0"?>
     <field2>this one</field2>
     <field2>another long field with lots of text in it</field2>

Once it's in XML, manipulation becomes much easier because it's now all
robustly addressable. From here on you can write an XSLT transformation
to put the values you want in the places and names that your Schema



These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.