Exercise


  1. Generate an XML file using a Perl data structure using the Perl print function and then again using the Perl XML::Writer module. The data structure consists of an array of hashes that holds email list information. Here is a sample data structure to use as input. Of course, you can change the data if you feel more comfortable using your personal information.

     my @list = ({                 first => 'Ilya',                 last => 'Sterin',                 email => 'isterin@cpan.org'              },              {                 first => 'Mark',                 last => 'Riehl',                 email => 'mark_riehl@hotmail.com'              }); 

The reason for using the data structure for an input data source is that it simulates XML generation as one part of a multistep process. For example, the XML document may get generated as a result of previous processing by the same application.

Which approach was easier? Can you see the benefit of the XML::Writer module in a long, complicated XML document?

The generated XML output file should conform to the following format:

 <email_list>    <name first="" last="" email=""/>    <name first="" last="" email=""/>      </email_list> 

Make sure you include a valid XML declaration with an encoding of your choice.

For suggested solutions to this exercise, be sure to check out the web site: http://www.xmlproj.com/book/chapter05.



XML and Perl
XML and Perl
ISBN: 0735712891
EAN: 2147483647
Year: 2002
Pages: 145

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net