Sample Input and Output

Sample Input and Output

We again use the simple address book listing for the example for this utility. Each row is an entry for a person. The columns are listed below.

  1. Last name

  2. First name

  3. Street address, first line

  4. Street address, second line

  5. City

  6. State or province

  7. Zip or postal code

  8. Country

  9. Phone number

  10. E-mail address

Here's a sample input CSV file for an address book in this format (simple.CSV).

"Jones","Mary","312 Renner Road","Apartment C","Richardson","TX","75080",
"Smith","Sue","Highway 118",,"Terlingua","TX","79852",
  ,,"[email protected]"
"Fred","Finger","PO Box 999",,"Nome","AK","99762",
  ,,"[email protected]"

Successful processing should produce an XML document that looks like the sample shown below.

Sample Output Document (SimpleCSV.xml)
<?xml version="1.0" encoding="UTF-8"?>
    <Column03>312 Renner Road</Column03>
    <Column04>Apartment C</Column04>
    <Column03> Highway 118</Column03>
    <Column10>[email protected]</Column10>
    <Column03>PO Box 999</Column03>
    <Column10>[email protected]</Column10>

Again, as with our example in the previous chapter, none of the rows have data for all the columns since some of them (such as column 4, the second line of the street address) are optional.

Using techniques that will be discussed in Chapter 10, we can easily convert this output into the following format using XSLT.

Sample Converted Output Document
<?xml version="1.0" encoding="UTF-8"?>
    <Street1>312 Renner Road</Street1>
    <Street2>Apartment C</Street2>
    <Street1>Highway 118</Street1>
    <E-Mail>[email protected]</E-Mail>
    <Street1>PO Box 999</Street1>
    <E-Mail>[email protected]</E-Mail>

You may ask, "Why not just create this output in the first place?" We certainly could, quite easily. However, this is intended to be a general purpose utility, not one used just to convert address books. So, the generic ColumnXX names are appropriate.

     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows