View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Code for writing to an XML file

fileXMLOut: aFileName
"Writes the instructions, including the name and description, out to the
specified xml file as strings with one information item (e.g. instruction
step) per line. If the aFileName is invalid, it prints an error to the
transcript and returns nil."
| aFile |
aFile _ FileStream fileNamed: aFileName.
aFile = nil
ifTrue: ["If the string passes is invalid for a file name."
Transcript show: 'The file name: ' , aFileName , ' is not valid.';
cr.
^ nil].
aFile nextPutAll: 'Unknown function: xml' , String cr.
aFile nextPutAll: '' , String cr.
aFile nextPutAll: ''
, (name
reject: [:c | c = String cr asCharacter]) , '
' , String cr.
aFile nextPutAll: ''
, (descr
reject: [:c | c = String cr asCharacter]) , '
' , String cr.
"Loops and writes all the steps."
1
to: steps size
do: [:index |
aFile nextPutAll: '' , String cr.
aFile nextPutAll: ''
, ((steps at: index) descr
reject: [:c | c = String cr asCharacter]) , '
' , String cr.
aFile nextPutAll: ''
, ((steps at: index) action
reject: [:c | c = String cr asCharacter]) , '
' , String cr.
aFile nextPutAll: ''
, ((steps at: index) checkAction
reject: [:c | c = String cr asCharacter]) , '
' , String cr.
aFile nextPutAll: '
' , String cr].
aFile nextPutAll: '
' , String cr.
"Ensure nothing else is in the file"
[aFile atEnd]
whileFalse: [aFile nextPutAll: ' '].
aFile close

Link to this Page