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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |