[#30722] JSON ライブラリの取り込み — "NARUSE, Yui" <naruse@...>

naruseです。

20 messages 2007/04/21

[ruby-dev:30721] [BUG?] XPath を利用したノード探索が失敗する

From: "Hirofumi HONDA" <h2onda@...>
Date: 2007-04-19 11:21:57 UTC
List: ruby-dev #30721
はじめまして。
ほんだと申します。

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 =  %|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <link rel="stylesheet" href="/css1.css" type="text/css" />
    <link rel="stylesheet" href="/css2.css" type="text/css" />
  </head>
</html>|

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
----------------------------------------------------

--
ほんだひろふみ

In This Thread

Prev Next