Ticket #102 (closed defect: fixed)
Cannot select attribute with default namespace
| Reported by: | kevinj | Owned by: | ser |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.1.8 |
| Component: | DOM | Version: | 3.1.6 |
| Severity: | normal | Keywords: | |
| Cc: | Ruby version: | Other | |
| Operating system: | Linux |
Description
In ruby 1.8.6, Element::attribute returns nil rather than the attribute when called with the default namespace:
Test case:
require 'rexml/document'
doc = REXML::Document.new '<doc xmlns="ns"><item name="foo"/></doc>' p doc.root.elementsitem?.attribute("name", "ns") p doc.root.elementsitem[@name='foo']?
Output with ruby 1.8.5:
$ ruby test.rb
name='foo' <item name='foo'/>
Output with ruby 1.8.6:
$ ruby test.rb
nil nil
The problem appears to have been introduced with this changeset: http://www.germane-software.com/projects/rexml/changeset/1237
The below patch seems to fix the issue:
--- /usr/lib/ruby/1.8/rexml/element.rb.bak 2007-05-08 11:18:39.000000000 -0700
+++ /usr/lib/ruby/1.8/rexml/element.rb 2007-05-08 11:18:41.000000000 -0700 @@ -558,6 +558,7 @@
def attribute( name, namespace=nil )
prefix = nil
prefix = namespaces.index(namespace) if namespace
+ prefix = nil if prefix == 'xmlns'
attributes.get_attribute( "#{prefix ? prefix + ':' : }#{name}" )
end
