0

我有一个格式如下的 xml 提要:

<league country="england">
 <match status="15:00" time="15:00">
   <home name="Newcastle Utd"/>
   <away name="Norwich"/>
  </match>
    <match status="15:00" time="15:00">
    <home name="Newcastle Utd"/>
    <away name="Norwich"/>
    </match>
    <match status="19:00" time="19:00">
    <home name="Swansea"/>
    <away name="Stoke City"/>
    </match>
 </league>

如何在 feedjira 中添加自定义解析器并将其用于此提要?谢谢

4

1 回答 1

0
require 'feedjira';
require './Custom.rb';
c = Feedjira::Feed.parse_with Custom::Custom, '<xml><title>TitlePArsed</title></xml>'
print c.title;

自定义.rb:

require 'feedjira';
module Custom
 # Parser for dealing with Atom feeds.
 class Custom
   include SAXMachine
   include Feedjira::FeedUtilities
   element :title

   def self.able_to_parse?(xml) #:nodoc:
      true
   end

   def url
     @url || (links - [feed_url]).last || links.last
   end

   def feed_url
     @feed_url ||= links.first
   end

   def self.preprocess(xml)
     Preprocessor.new(xml).to_xml
   end
 end
end
于 2015-10-18T07:40:32.727 回答