From: Hirofumi HONDA Date: 2007-04-19T20:21:57+09:00 Subject: [ruby-dev:30721] [BUG?] XPath を利用したノード探索が失敗する はじめまして。 ほんだと申します。 REXML のバグらしきものを発見したので報告します。 ruby 1.8.6 で以下のコードを実行すると、 namespace が設定されている xml で ノード探索が失敗します。 ---------------------------------------------------- require 'rexml/document' puts "RUBY_VERSION = %s" % RUBY_VERSION puts "REXML::VERSION = %s" % REXML::VERSION puts "PLATFORM = %s" % PLATFORM xhtml = %| | docs = Array.new(2) do REXML::Document.new(xhtml) end docs[1].root.delete_namespace xpath = %|html/head/link[attribute::rel="stylesheet"]| puts "XPath = %s" % xpath docs.each do |doc| elements = doc.get_elements(xpath) puts "namespace = %s" % doc.root.namespace puts "nodes size = %s" % elements.size end ---------------------------------------------------- ・1.8.6 の出力 ---------------------------------------------------- RUBY_VERSION = 1.8.6 REXML::VERSION = 3.1.6 PLATFORM = i486-linux XPath = html/head/link[attribute::rel="stylesheet"] namespace = http://www.w3.org/1999/xhtml nodes size = 0 namespace = nodes size = 2 ---------------------------------------------------- ・1.8.5 の出力 ---------------------------------------------------- RUBY_VERSION = 1.8.5 REXML::VERSION = 3.1.4 PLATFORM = i686-linux XPath = html/head/link[attribute::rel="stylesheet"] namespace = http://www.w3.org/1999/xhtml nodes size = 2 namespace = nodes size = 2 ---------------------------------------------------- -- ほんだひろふみ