如何在Perl中创建XML模板?
我需要创建的XML文件如下如何在Perl中创建XML模板?,xml,perl,templates,Xml,Perl,Templates,我需要创建的XML文件如下 <file> <state>$state</state> <timestamp>$time</timestamp> <location>$location</location> .... </file> $state $time $location .... 我不想使用多次打印来创建所需的XML文件,我希望有一个模板,
<file>
<state>$state</state>
<timestamp>$time</timestamp>
<location>$location</location>
....
</file>
$state
$time
$location
....
我不想使用多次打印来创建所需的XML文件,我希望有一个模板,它定义XML的结构和格式
然后在创建XML文件时,我只需要提供模板中变量的实际值,并将指定的模板写入新创建的文件一次,仅一次。有几个XML模块可以使用
我的建议是从或开始,您可以使用
#/usr/bin/perl
严格使用;
使用警告;
使用HTML::模板;
我的$template\u text=\$template\u text);
$tmpl->param(
文件=>[
{状态=>'1',时间=>'2',位置=>'3'},
{state=>alpha',time=>beta',location=>gamma'},
]);
打印$tmpl->输出;
输出:
<file>
<state>one</state>
<timestamp>two</timestamp>
<location>three</location>
</file>
<file>
<state>alpha</state>
<timestamp>beta</timestamp>
<location>gamma</location>
</file>
一
二
三
阿尔法
贝塔
伽马射线
答案正是我需要的。
<file>
<state>one</state>
<timestamp>two</timestamp>
<location>three</location>
</file>
<file>
<state>alpha</state>
<timestamp>beta</timestamp>
<location>gamma</location>
</file>