Ruby nokogiri 解析xml的简单实例

require 'nokogiri'
XML_FILE = "C:\Users\chenpassion\Desktop\20130806.xml"
xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
xml.xpath('//NewspaperReport').each {|x|
    if !x.attributes.include?("DownloadState") || x.attributes["DownloadState"].value != "下载完成"
        puts x.attributes["ChineseName"].value
    end
    }

我想把XML中下载失败的报纸列出来,可以用以上的方法。

原文地址:https://www.cnblogs.com/autotest/p/3270172.html