Let's suppose that you have a list of states in a file called c:/states.txt in the following format:
AL ALABAMA AK ALASKA AZ ARIZONA AR ARKANSAS CA CALIFORNIA ...Instead of this format, you need an XML file as shown below:
<FILE> <AL>ALABAMA</AL> <AK>ALASKA</AK> <AZ>ARIZONA</AZ> <AR>ARKANSAS</AR> <CA>CALIFORNIA</CA> ... </FILE>
(Note: XML files use tags similar to HTML. Don't worry if you do not know XML, just understand that the goal is to change from the first format to the second format.)
We will open c:/states.txt as file 1, and open c:/states.xml as file 2. We will read a line from file 1, parse it and write a line in XML format to file 2. In additions, file 2 will have the two lines at the start and end of the file.
Although the complete list of states is not shown here, bear in mind that there are some states, like New York, that have a space in the name!