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

This will include all the content of XInclude files - I don't need that. I need a list of their filepaths

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

Replies are listed 'Best First'.
Re^3: XML::LibXML question: How to list XInclude files, which are supposed to be included?
by toolic (Bishop) on Jul 06, 2011 at 18:05 UTC
    Can you just parse the include tag just like any other tag?

    I don't know how to use XML::LibXML, but this is simple using XML::Twig

    use warnings; use strict; use XML::Twig; my $myXML = <<EOF; <?xml version="1.0"?> <reports xmlns:xi="http://www.w3.org/2001/XInclude"> <xi:include href="xinclude.xml" parse='xml' /> </reports> EOF my $t = XML::Twig->new(twig_handlers => {'xi:include' => sub { print $ +_->att('href') } }); $t->parse($myXML); __END__ xinclude.xml

      Hum, something's not right because you use a prefix you never define.

      Yup, doesn't work :( It only finds one of the includes in

      <?xml version="1.0"?> <reports xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xinclude="http://www.w3.org/2001/XInclude"> <xi:include href="xinclude.xml" parse="xml" /> <xinclude:include href="xinclude.xml" parse="xml" /> <include xmlns="http://www.w3.org/2001/XInclude" href="xinclude.xml" p +arse="xml" /> </reports>

      I never used the XML::Twig... and it's not installed on my system now. It's big! but it might help though...

      I hoped to remain in the XML::LibXML realm actually

      Thanks

      Alex

        The Swiss Army Knife® of XML in Perl ... IMHO ... is a twig.