本文介绍了如何在Perl中使用XML文件中的数据生成PDF文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我如何使用模板工具包读取此信息

Hi how can I read this information using template toolkit

 $var1= {
  'STC'=>[
     {
        'gym'=>{
              'hyd'=>{
                   'com'=>[
                        'dr'=>'1',
                         'typ'=>'z',
                          'bemo'=>{
                               'bm'=>'1',
                                'typ'=>'x',
                                'col'=>'red'
                                 }
                               }
                            {
                          'dr'=>'12',
                         'typ'=>'a',
                          'bemo'=>{
                               'bm'=>'25',
                                'typ'=>'p',
                                'col'=>'red'
                                 }
                            }
                         {
                          'dr'=>'23',
                         'typ'=>'k',
                          'bemo'=>{
                               'bm'=>'22',
                                'typ'=>'w',
                                'col'=>'blue'
                                 }
                            }
                          {
                          'dr'=>'3',
                         'typ'=>'s',
                          'bemo'=>{
                               'bm'=>'9',
                                'typ'=>'B',
                                'col'=>'green'
                                 }
                            }

                          }
                       }
                      ]
                     };

我无法获得这种复杂的数据,无法解决所有问题,并且可以根据需要获取输出,但是这个问题困扰着我.请帮帮我.

I am not able to get this type of complex data , Remaining everything I solved and I am getting output as I want but this problem suffers me.please help me.

推荐答案

好的,所以您有一些数据,您希望它看起来像什么?您可能会在文本编辑器中打开并打印pdf或另存为rtf,从而冒着听起来有些nar昧的风险.显然,这不是您的意思.

ok so you have some data, what do you expect it to look like? At the risk of sounding snarky, you could simply open in a text editor and print pdf or save as rtf. Clearly this isn't what you mean.

您需要以某种方式格式化数据.然后,转换将只是将您的数据应用到该格式.

You need to format the data somehow. Then the conversion will simply be the application of that your data to that format.

正如我在此处所述,您可以制作LaTeX模板并用您的数据填写 Template::Toolkit 并使用LaTeX编译器进行编译.这将为您提供PDF.

As I mention here, you could make a LaTeX template and fill it in with your data and Template::Toolkit and compile using a LaTeX compiler. This would get you a PDF.

#!/usr/bin/env perl

use strict;
use warnings;

use XML::Fast;
use Template;

my $xml = <<'XML';
 <student>
      <number>24</number>
      <education>bachelors</education>
      <specialization>computers </specialization>
     -<address>
         <house_number="128"/>
         <street name="xxxx"/>
           <proddutoor/>
      <address/>
     -<details>
          <name="clar"/>
          <age="20"/>
         <sex="m"/>
       </details>
</student>
 <student>
      <number>23</number>
      <education>ph.d.</education>
      <specialization>physics </specialization>
     -<address>
         <house_number="128"/>
         <street name="xxxx"/>
           <proddutoor/>
      <address/>
     -<details>
          <name="joel"/>
          <age="20"/>
         <sex="m"/>
       </details>
</student>
XML
my $xml_hash = xml2hash $xml;

my $template = Template->new();

my $filename = 'output.tex';

#I think the following is a holdover from a previous version
#as I cannot check right now, I will leave as a comment:
#open my $fh, '>', $filename;

$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.degree %] student.

[% END %]

\end{document}

XML::Fast甚至对格式不佳的XML都表现出色:)

N.B. XML::Fast even does surprisingly well against your poorly formatted XML :)

这篇关于如何在Perl中使用XML文件中的数据生成PDF文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:29