Exercises

  1. Given the CSV data shown in the following, create a file named exer_1.csv. Write a Perl program using the XML::SAXDriver::XML module that will convert the CSV file to XML.

    Name the root element <exercise1> and then use the first column names as the element names (hint: Dynamic_Col_Headings). Use the XML::Handler::YAWriter as the event handler. Generate a new file named exer_1.xml containing the results.

    Class,Teacher,Time,Room,Lab 
    Biology,Mrs. Riehl,10:00 − 11:00,103,Y 
    Marine Science,Mrs. Riehl,11:30 − 12:30, 103,N 
    Algebra,Mr. McCarthy,1:00 − 2:00,114,N 
    Computer Science,Mr. Burns,3:00 − 4:00,204,Y 
  2. Now modify the program and write your own handler to handle the CSV data. Don’t forget to take out the XML::Handler::YAWriter dependency ...

Get XML and Perl now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.