一、安装nokogiri
gem 'nokogiri'
执行 bundle install
二、使用
NetHelp内方法
def self.read_xml_file(url_xml)
xml = Nokogiri::XML(File.open(url_xml))
xml
end
调用方法
xml = NetHelp.read_xml_file("#{Rails.root}/lib/demo.xml")
tds = xml.xpath("//body")
Rails.logger.info "====#{tds[0].content }"
==># [<body>Don't forget the meeting!</body>,<body>Don't forget the meeting!111</body>,<body>Don't forget the meeting!222</body>]
==># Don't forget the meeting!