我是 Perl 脚本的新手。我需要帮助来获取总警报的 XML 属性值(在本例中为 11)。
<?xml version="1.0" encoding="utf-8"?>
<alarm-response-list xmlns="url.com" throttle="11" total-alarms="11">
<alarm-responses>
<alarm id="51ebf6fc-0571-1001-0162-008014000af00" />
<alarm id="51ec0320-07af-1001-0162-008010400af00" />
<alarm id="51ebf6f4-0564-1001-0162-008014000af00" />
<alarm id="51ec1512-0bb2-1001-0162-008010400af00" />
<alarm id="51ec157d-0bed-1001-0162-008010040af00" />
<alarm id="51ebae1b-fa31-1000-0162-008010004af00" />
<alarm id="51ec06d4-08bf-1001-0162-00801000a4f00" />
<alarm id="51e8303f-740a-1000-0162-008014000af00" />
<alarm id="51ebeabc-0352-1001-0162-008010400af00" />
<alarm id="51ebf74d-0593-1001-0162-008010040af00" />
<alarm id="51ebf78d-05b3-1001-0162-008010004af00" />
</alarm-responses>
</alarm-response-list>
不成功,我尝试使用以下 Perl 代码:
my $parser4 = XML::LibXML->new();
my $doc4 = $parser4->parse_file($current_working_dir.'\POSTres.xml');
my $xc = XML::LibXML::XPathContext->new( $doc4->documentElement() );
my $nod = $xc->findnodes('//alarm-response-list');
print "A: ".$nod->getAttributes("total-alarms")."\n";
任何想法?