Permalink
Browse files

[FEATURE] XPath lookup with namespaces with hash keys

  • Loading branch information...
1 parent 3bea293 commit 44d1c3ec9c5c82b7285ed4a6c100b776c7cf7899 @benlangfeld benlangfeld committed Jul 13, 2012
Showing with 17 additions and 1 deletion.
  1. +1 −1 lib/nokogiri/xml/xpath_context.rb
  2. +16 −0 test/xml/test_node.rb
@@ -6,7 +6,7 @@ class XPathContext
# Register namespaces in +namespaces+
def register_namespaces(namespaces)
namespaces.each do |k, v|
- k = k.gsub(/.*:/,'') # strip off 'xmlns:' or 'xml:'
+ k = k.to_s.gsub(/.*:/,'') # strip off 'xmlns:' or 'xml:'
register_ns(k, v)
end
end
View
@@ -835,6 +835,22 @@ def test_namespace_search_with_xpath_and_hash
assert_equal 1, tires.length
end
+ def test_namespace_search_with_xpath_and_hash_with_symbol_keys
+ xml = Nokogiri::XML.parse(<<-eoxml)
+ <root>
+ <car xmlns:part="http://general-motors.com/">
+ <part:tire>Michelin Model XGV</part:tire>
+ </car>
+ <bicycle xmlns:part="http://schwinn.com/">
+ <part:tire>I'm a bicycle tire!</part:tire>
+ </bicycle>
+ </root>
+ eoxml
+
+ tires = xml.xpath('//bike:tire', :bike => 'http://schwinn.com/')
+ assert_equal 1, tires.length
+ end
+
def test_namespace_search_with_css
xml = Nokogiri::XML.parse(<<-eoxml)
<root>

0 comments on commit 44d1c3e

Please sign in to comment.