in reply to XML::LibXML question: How to list XInclude files, which are supposed to be included?

I've written a small recursive sub, which looks into the XML file and finds out all the XInclude'd filenames, then calls itself on all these files (it doesn't expand XInclude's)

If any interest, I'll post it here...

Thanks
Alex
  • Comment on Re: XML::LibXML question: How to list XInclude files, which are supposed to be included?

Replies are listed 'Best First'.
Re^2: XML::LibXML question: How to list XInclude files, which are supposed to be included?
by ikegami (Patriarch) on Jul 07, 2011 at 01:18 UTC
    So did I. How does it differ from mine?
      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";