REXX's powerful PARSE command has the ability to parse fixed-length
fields. It is messy and some what difficult to set up but it works.
/* open the raw data file for reading
*/
RawDataFile = "2001Stus.txt"
/* hard wire for now - use arg later */
OneRawDataLine = linein(RawDataFile)
/* this line of raw data is column headings - discard */
/* read in the raw data */
numStu = 0
do while lines(RawDataFile)
numStu = numStu + 1
OneRawDataLine = linein(RawDataFile)
/* this line is real data */
/* parse the raw data line */
parse value OneRawDataLine
with ,
1 Chunk.numStu.FName
41 ,
42 Chunk.numStu.LName
82 ,
83 Chunk.numStu.Addreess
123 ,
124 Chunk.numStu.City
164 ,
165 Chunk.numStu.Zip
205 ,
206 Chunk.numStu.HomeFone
246 ,
247 .
287 ,
288 Chunk.numStu.Parent
328 ,
329 .
/* remove extraneous spaces
*/
Chunk.numStu.FName
= strip(Chunk.numStu.FName)
Chunk.numStu.LName
= strip(Chunk.numStu.LName)
Chunk.numStu.Addreess = strip(Chunk.numStu.Addreess)
Chunk.numStu.City
= strip(Chunk.numStu.City)
Chunk.numStu.Zip
= strip(Chunk.numStu.Zip)
Chunk.numStu.HomeFone = strip(Chunk.numStu.HomeFone)
Chunk.numStu.Parent
= strip(Chunk.numStu.Parent)
end /* do while lines(RawDataFile) */
/* save the number of students */
Chunk.0 = numStu
/* create an XML document */
say '<?xml version="1.0" ?>'
say '<document type="Roster of Students"'
say ' name="Eastside
Christian High School"'
say ' SchoolYear="2001
- 2002"'
say ' Semester="Fall
2002">'
say ' <Students>'
do numStu = 1 to Chunk.0
say ' <Student>' /* student
may repeat more than once */
say ' <FirstName>'||Chunk.numStu.FName||'</firstname>'
say ' <LastName>'||Chunk.numStu.LName||'</lastname>'
say ' <CallBy></CallBy>'
say ' <ContactAddress>'
say ' <Adderss>'||Chunk.numStu.Addreess||'</address>'
say ' <City>'||Chunk.numStu.City||'</city>'
say ' <zip>'||Chunk.numStu.Zip||'</zip>'
say ' <e-Mail></e-mail>'
say ' <Phone>'||Chunk.numStu.HomeFone||'</Phone>'
say ' </ContactAddress>'
say ' <Classes>'
say ' <class>'
/* class may repeat more than once for any one student */
say '
<Subject></Subject>'
say '
<Period></Period>'
say '
<teacher><teacher>'
say ' </class>'
say ' </Classes>'
say ' </student>'
end /* numStu = 1 to Chunk.0 */
say ' </Students>'
say '</document>'