XPathを使ってみる
XPathとかって存在は知ってても使ったことが無かったので使ってみる。
Amazonのwsdlをとってきて、OperationをXPathでmatchして並べる。
require 'open-uri' require 'rexml/document' uri = "http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl" doc = REXML::Document.new(open(uri).read) ops = REXML::XPath.match(doc.root, "//operation") ops = ops.inject([]) {|result, o| if not result.include? o.attributes["name"] result << o.attributes["name"] end result }.sort ops.each {|x| puts "#{x}\n" } puts "Total number of operations: #{ops.length}"