Use Data::Dumper or similar to view the structure of your data. The following should get you close to the output you're looking for.

#!/usr/bin/env perl use strict; use warnings;
use XML::Fast; use Template; use Data::Dumper; my $xml = <<'XML'; <student> <number>24</number> <education>bachelors</education> <specialization>computers</specialization> <address> <house_number>128</house_number> <street_name>xxxx</street_name> <proddutoor/> </address> </student> <student> <number>23</number> <education>ph.d.</education> <specialization>physics</specialization> <address> <house_number>12</house_number> <street_name>yyyy</street_name> <kadapa/> </address> </student> XML my $xml_hash = xml2hash $xml; print Dumper($xml_hash),$/; my $template = Template->new(); my $filename = 'output.tex'; $template->process(\*DATA, $xml_hash, $filename) || die "Template process failed: ", $template->error(), "\n"; system( "pdflatex $filename" ); __DATA__ \documentclass{article} \title{Roster} \author{pavani} \begin{document} \maketitle [% FOREACH st IN student %] Student [% st.number %] is a [% st.specialization %] [% st.education % +] student and his address is [% st.address.house_number +%] [% st.add +ress.street_name %]. [% END %] \end{document}

As for reading the XML from file you can just slurp it in:

t.xml =
<student> <number>24</number> <education>bachelors</education> <specialization>computers</specialization> <address> <house_number>128</house_number> <street_name>xxxx</street_name> </address> </student> <student> <number>23</number> <education>ph.d.</education> <specialization>physics</specialization> <address> <house_number>12</house_number> <street_name>yyyy</street_name> </address> </student> <student> <number>22</number> <education>BS</education> <specialization>Biology</specialization> <address> <house_number>123</house_number> <street_name>zzzz</street_name> </address> </student> <student> <number>21</number> <education>MS</education> <specialization>Agronomy</specialization> <address> <house_number>321</house_number> <street_name>aaaa</street_name> </address> </student> <student> <number>20</number> <education>Ph.D</education> <specialization>sociology</specialization> <address> <house_number>333</house_number> <street_name>bbbb</street_name> </address> </student> -- end t.xml #!/usr/bin/env perl use strict; use warnings; use XML::Fast; use Template; use Data::Dumper; my $xmlfile = 't.xml'; my $xml; { open my $xml_fh, '<', $xmlfile or die "cannot open $xmlfile: $!\n"; $/ = ''; $xml = <$xml_fh>; close $xml_fh; } print Dumper($xml),$/; my $xml_hash = xml2hash $xml; print Dumper($xml_hash),$/; my $template = Template->new(); my $filename = 'output.tex'; $template->process(\*DATA, $xml_hash, $filename) || die "Template process failed: ", $template->error(), "\n"; system( "pdflatex $filename" ); __DATA__ \documentclass{article} \title{Roster} \author{pavani} \begin{document} \maketitle [% FOREACH st IN student %] Student [% st.number %] is a [% st.specialization %] [% st.education % +] student and his address is [% st.address.house_number +%] [% st.add +ress.street_name %]. [% END %] \end{document}


In reply to Re: errors in printing latex template output by keszler
in thread errors in printing latex template output by veerubiji

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.