How can I get XML::RSS to read XML elements in a different namespace?

66 views Asked by At

Given this RSS content, which features the non-standard namespace 'torznab':

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:torznab="http://torznab.com/schemas/2015/feed">
  <channel>
    <title>AggregateSearch</title>
    <description>This feed includes all configured trackers</description>
    <link>http://127.0.0.1/</link>
    <language>en-US</language>
    <category>search</category>
    <item>
      <title>Yellowjackets.S02E08.It.Chooses.720p.AMZN.WEBRip.DDP5.1.x264-NTb[rartv]</title>
      <guid>https://rarbg.to/infohash/4ce37b2cd4157349a6eb2e6100513e8946fbdcac</guid>
      <jackettindexer id="rarbg">RARBG</jackettindexer>
      <type>public</type>
      <comments>https://torrentapi.org/redirect_to_info.php?token=0186pk4m73</comments>
      <pubDate>Fri, 19 May 2023 23:21:30 +1000</pubDate>
      <size>920749041</size>
      <description />
      <link>magnet:?xt=urn:btih:4ce37b2cd4157349a6eb2e6100513e8946fbdcac</link>
      <category>5040</category>
      <category>100041</category>
      <enclosure url="magnet:?xt=urn:btih:4ce37b2cd4157349a6eb2e6100513e8946fbdcac" length="920749041" type="application/x-bittorrent" />
      <torznab:attr name="seeders" value="279" />
      <torznab:attr name="peers" value="353" />
    </item>
  </channel>
</rss>

If I want to parse it using XML::RSS and get access to those <torznab:attr /> elements, I should be able to do it by adding that namespace, as in this minimal script:

use XML::RSS;
use Data::Dumper;
my $rss = XML::RSS->new();
# add the special namespace before parsing
$rss->add_module(
    prefix => 'torznab',
    uri    => "http://torznab.com/schemas/2015/feed"
);
$rss->parsefile("torznab.xml");
say Dumper($rss);
say Dumper( $rss->{items}->[0] );

But when I do that, the elements just aren't there in the output.

What am I missing? TIA.

0

There are 0 answers