Changeset 375

Show
Ignore:
Timestamp:
03/09/06 06:38:15
Author:
miyagawa
Message:

use LibXML in Bulkfeeds API. Fixes #114

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/Makefile.PL

    r363 r375  
    106106    'Filter::BulkfeedsTerms' => [ 
    107107        -default => 0, 
    108         recommends('XML::Simple'), 
     108        recommends('XML::LibXML'), 
    109109    ], 
    110110    'Publish::HatenaBookmark' => [ 
  • trunk/plagger/lib/Plagger/Plugin/Filter/BulkfeedsTerms.pm

    r215 r375  
    55use Encode; 
    66use Plagger::UserAgent; 
    7 use XML::Simple
     7use XML::LibXML
    88use URI; 
    99 
     
    3535    } 
    3636 
    37     my @terms = grep !ref, @{ XMLin($res->content)->{term} }; 
     37    my @terms = eval { $self->parse_terms($res->content) }; 
    3838    $context->log(info => "Terms for " . $args->{entry}->link . ": " . join(", ", @terms)); 
    3939 
     
    4141        $args->{entry}->add_tag($term); 
    4242    } 
     43} 
     44 
     45sub parse_terms { 
     46    my($self, $xml) = @_; 
     47    my $doc = XML::LibXML->new->parse_string($xml); 
     48 
     49    my @terms; 
     50    for my $node ( $doc->findnodes('/terms/term')->get_nodelist ) { 
     51        my $term = $node->textContent; 
     52        push @terms, $term if defined $term && $term ne ''; 
     53    } 
     54 
     55    return @terms; 
    4356} 
    4457