Hi,

I am very new to Perl and XML so please forgive me if I sound like a noob.

In my .pl I am using XML::Simple, Data::Dumper, and HTML::Template to try to display info from an xml file to an html template. I have read and reread the CPAN articles for all the mods I am using, but still can't figure this out.

My XML looks like this:
<document> 'employee' =>{ 'department' => [ 'Operations Hardware', 'Corporate Marketing', 'Legal', 'Human Resources', 'Finance' ] } </document>
To get this in perl I have:
#!/perl #use strict; use lib 'C:/xampp/perl/site/lib'; use HTML::Template; $ENV{XML_SIMPLE_PREFERRED_PARSER} = 'XML::Parser';<br< use XML::Simple; use Data::Dumper; my $template = HTML::Template->new(filename => 'file'); my $xml = XMLin('file', ForceArray => ['option']); my @deptartment = @{ $xml->{employee}->{department} }; $template->param(DEPT => @deptartment); print $template->output;
and in my .tmpl I have:
<+font size="4">Department: </+font> <+ul><+li><select name="dept"> <TMPL_LOOP DEPT> <option value="<TMPL_VAR EMP_DEPT>"><TMPL_VAR EMP_DEPT></option> + </TMPL_LOOP> </select></+li> </+ul>

I'm not getting any errors, but the drop-down list in the html that gets displayed is empty. I have a feeling that I'm either (1) not getting the data from the .xml correctly, or (2) not giving the .tmpl the data in the correct format.

Please help!

In reply to Problems getting info from .xml to display with HTML::Template by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.