我正在尝试从以下结构的XML文件中提取两个特定属性的值:
<environment>
<applications>
<application1>
<app-config>
<server host="boxA" port="1234"/>
</app-config>
</applicaitons>
</environment>
我希望能读取属性“host”和“port”的值。
我已经尝试过下面的代码,但对我来说不起作用。
#!/usr/local/bin/perl -w
use XML::XPath;
my $file = "configuration.xml";
my $xp = XML::XPath->new(filename => $file);
my $hname = $xp->find('/environment/applications/application1/app-config/server/@host');
my $pnumber = $xp->find('/environment/applications/application1/app-config/server/@port');
print $hname;
当我运行这个命令时,它没有返回任何输出。提前致谢。