TEXT FILE DATA AND XML SERIALIZATION
In this section the functions to read and write the tracks data to a text file and with an XML file are implemented. The sample code as supplied has this implementation of the read and write functions.
Reading and Writing to a Text File
The playlist could be stored as a Comma Separated Values (CSV) text file. A CSV file is a text file consisting of lines as records. Each field value for a record is sequentially listed in the line separated by a comma. Text files are a universal way for passing data around because most computer applications can load, save, and transport them.
A music playlist would have tracks as records, with the following field values on every line: Track Number, Title, Artist, and Album.
If you were to save the music list data generated by the function CreateData(), as a CSV file, it would be written into a text file in the following format:
1, The Fool on the Hill, Beatles, Magical Mystery Tour
2, Chasing Pirates, Norah Jones, The Fall
3, Man of The Hour, Norah Jones, The Fall
4, Love of My Life, Queen, A Night At The Opera
Often the first line of such files would be a header which lists the field names in order. The Track Number possibly would not be stored because this would be generated from the order that it is read back in by.
CSV Text File Write Example
This code implements the process of writing the track information to a CSV text file. It also includes the name of the text file to which the data will be written ...