Xml findnodes找不到给定的路径

Xml findnodes找不到给定的路径,xml,perl,Xml,Perl,关于Perl中的findnodes,我有一个简单的问题。假设我有以下示例XML(test.XML)文件作为输入 <SquishReport version="2.1" xmlns="http://www.froglogic.com/XML2"> <test name="mainTest1"> <test name="test1"> </test> <test name="test2"&

关于Perl中的
findnodes
,我有一个简单的问题。假设我有以下示例
XML
test.XML
)文件作为输入

<SquishReport version="2.1" xmlns="http://www.froglogic.com/XML2">
    <test name="mainTest1">
        <test name="test1">

        </test>
        <test name="test2">

        </test>
    </test>
    <test name="mainTest2">
        <test name="test3">

        </test>
        <test name="test4">

        </test>
    </test>
</SquishReport>
但在运行了上面的代码之后,我得到了一个空列表。我发现如果我在根节点(
SquishReport
)中删除了其余的解释,即

version=“2.1”xmlns=”http://www.froglogic.com/XML2"

然后一切正常,我就有了想要的输出。但如果我把上面的解释包含在主根中,情况就不一样了


有人知道为什么会这样吗?谢谢

顺便说一下,一定要使用
严格使用。我们通常会在答案中忽略它,因为它总是被使用。
XML::Twig
是名称空间盲的,因此这种
findnodes
操作将在不需要处理名称空间的情况下工作。(这是一个bug还是一个特性是另一个问题)非常感谢您的回答。
use warnings;
use XML::LibXML;
my $file = 'test.xml';
my $xpc = XML::LibXML::XPathContext->new();
$xpc->registerNs(fl => 'http://www.froglogic.com/XML2');             # <---
my $doc = XML::LibXML->load_xml(location => $file);
for my $entry ($xpc->findnodes('//fl:SquishReport/fl:test', $doc))   # <---
{
    $testCases[$count] = $entry->getAttribute('name');
    $count = $count + 1;
}
print @testCases;
print "\n";
use warnings;
use XML::LibXML;
my $file = 'test.xml';
my $xpc = XML::LibXML::XPathContext->new();
$xpc->registerNs(fl => 'http://www.froglogic.com/XML2');             # <---
my $doc = XML::LibXML->load_xml(location => $file);
for my $entry ($xpc->findnodes('//fl:SquishReport/fl:test', $doc))   # <---
{
    $testCases[$count] = $entry->getAttribute('name');
    $count = $count + 1;
}
print @testCases;
print "\n";
use strict;
use warnings qw( all );

use XML::LibXML               qw( );
use XML::LibXML::XPathContext qw( );

my $qfn = 'test.xml';

my $doc = XML::LibXML->load_xml( location => $qfn );

my $xpc = XML::LibXML::XPathContext->new();
$xpc->registerNs(fl => 'http://www.froglogic.com/XML2');

my @test_cases;
for my $entry ($xpc->findnodes('//fl:SquishReport/fl:test', $doc)) {
    push @test_cases, $entry->getAttribute('name');
}

print "@testCases\n";