【发布时间】:2014-01-15 10:35:46
【问题描述】:
我想使用 perl 解析 xml 文件,我想检索 Audit 标签的值,但没有产生输出。
use strict;
use warnings;
use XML::Simple;
use Data::Dumper;
my $xml = <<'__EOI__';
<scanJob>
<hosts>
<host>
<audit>
<rthID>31406</rthID>
<cve>N/A</cve>
<cce>N/A</cce>
<iav>N/A</iav>
<name>OpenSSH Memory Corruption Vulnerability - (20131108) - Banner</name>
<description>OpenSSH 6.4 </description>
<pciReason>Default</pciReason>
<pciPassFail>Pass</pciPassFail>
<cvssScore>N/A</cvssScore>
<fixInformation>Upgrade OpenSSH 6.4 or later.</fixInformation>
<exploit>No</exploit>
<context>TCP:22</context>
</audit>
</host>
</hosts>
</scanJob>
__EOI__
my $xs = new XML::Simple;
my $data = $xs->XMLin(\$xml);
for my $scanJob (@{$data->{scanJob} }) {
for my $hosts (@{$scanJob->hosts }) {
for my $host (@{$hosts->host }) {
for my $audit (@{$host->audit }) {
my $rthID = $audit->{rthID};
print $rthID;
}
}
}
}
【问题讨论】:
-
你能发布你试图解析的 XML 吗?
-
31406 N/A N/A N/A OpenSSH 内存损坏漏洞 - (20131108) - Banner OpenSSH 6.4 Default Pass N/A 升级 OpenSSH 6.4 或更高版本。 No TCP:22 -
你不能编辑你的帖子吗?很难从评论中阅读它
-
我无法正确编辑这个?只想说标签对齐如下
-> -> -> -> 表示 rthID 是审计的孩子,审计是主机的孩子,主机是主机的孩子, hosts 是 scanJob 的子节点 -
@mirod 你能看看吗?