用Ruby编写的XML/HTML解析器:Oga

jopen 9年前

Oga是一个采用Ruby编写的XML/HTML解析器。它提供了一个易于使用的API来解析,修改和查询文档(使用XPath表达式)。Oga不需要系统库如libxml,使得它能够更简便和更快的安装在各种平台上。为了达到更好的性能Oga使用一个很小,原生扩展(C for MRI/Rubinius, Java for JRuby)。

handle = File.open('path/to/file.xml')  parser = Oga::XML::PullParser.new(handle)    parser.parse do |node|    parser.on(:text) do      puts node.text    end  end

特性

  • Support for parsing XML and HTML(5)
    • DOM parsing
    • Stream/pull parsing
    • SAX parsing
  • Low memory footprint
  • High performance, if something doesn't perform well enough it's a bug
  • Support for XPath 1.0
  • CSS3 selector support
  • XML namespace support (registering, querying, etc)

项目主页:http://www.open-open.com/lib/view/home/1417503470936