Hi, Ikegami:
My code is below - it's not drastically different from yours one. You're right - recursion is unavoidable. I hoped to avoid that with some XML::LibXML options - no way...
Thanks
Alex
my @list = ();
my $parser = XML::LibXML->new();
sub Process($)
{
my $f = shift;
if (-f $f and -r $f)
{
if (scalar(grep($_ eq $f, @list)) == 0)
{
push @list, $f;
my $root = $parser->parse_file($f)->documentElement();
my $prefix = $root->lookupNamespacePrefix('http://www.w3.org/200
+1/XInclude');
if ($prefix)
{
my $ok = 1;
foreach my $xincludeNode ($root->getElementsByTagName("$prefix:inc
+lude"))
{
my $xincludeFilename = File::Spec->rel2abs($xincludeNode->getAtt
+ribute('href'));
$ok &&= Process($xincludeFilename);
}
return $ok;
}
else
{
return 1;
}
}
else
{
return 1;
}
}
else
{
print STDERR "The file '$f' isn't found or not readable\n";
return 0;
}
}
Process(File::Spec->rel2abs($ARGV[0]));
my $list = join("\n", @list);
print $list, "\n";
|