XML : Perl / XML::LibXML no parsing due to namespace [duplicate]

This question already has an answer here:

I used XML::XPath to parse an xml-file and I encountered no problem. For several reason (not mantained (?), slowly, see for example here) I try XML::LibXML but don't succeed. The problem seems to be in the root of the xml-file. The following code does work:

  use strict;   use warnings;  use XML::LibXML;    my $prsr = XML::LibXML->new();  $prsr->keep_blanks(0);  my $xp = $prsr->parse_fh(\*DATA);    my @node_article = $xp->findnodes('/ARTICLE/*');    foreach my $node (@node_article) {      print "$node\n\n";  }    __DATA__    <ARTICLE xmlns:xsd="http://whatever" xmlns:xsi="http://whatever">      <EVENT name="cat1" />        <EVENT name="cat2" />        <EVENT name="cat3" />        <EVENT name="cat4" />        <EVENT name="cat5" />      </ARTICLE>    

enter image description here

But if the root contains the default namespace xmlns="http://whatever" the code above does not work (no output to terminal).

  __DATA__    <ARTICLE xmlns:xsd="http://whatever" xmlns:xsi="http://whatever" xmlns="http://whatever">      <EVENT name="cat1" />        <EVENT name="cat2" />        <EVENT name="cat3" />        <EVENT name="cat4" />        <EVENT name="cat5" />      </ARTICLE>    

One solution could be to delete (manually) the namespace but I want to avoid this since the original file will be downloaded and imported perdiodically. So, I have two questions:

  1. Why the namespace does cause the problem using XML::LibXML but not when using XML::XPATH
  2. How can I solve this problem using XML::LibXML?

Thanks for help.

No comments:

Post a Comment