Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node#remove_namespaces! breaks Node#> #294

Closed
flavorjones opened this issue Jun 15, 2010 · 2 comments
Closed

Node#remove_namespaces! breaks Node#> #294

flavorjones opened this issue Jun 15, 2010 · 2 comments

Comments

@flavorjones
Copy link
Member

#! /usr/bin/env ruby

require "rubygems"
require "nokogiri"

xml_with_ns = <<-EOXML
<?xml version="1.0" ?>
<root xmlns="http://foo.example.com/">
  <aaa> <bbb /> </aaa>
</root>
EOXML

xml_without_ns = <<-EOXML
<?xml version="1.0" ?>
<root>
  <aaa> <bbb /> </aaa>
</root>
EOXML

doc = Nokogiri::XML(xml_with_ns)
doc.remove_namespaces!
doc.xpath("//aaa").each do |node|
  puts (node > "bbb").inspect
  # => []
end

# for comparison
doc = Nokogiri::XML(xml_without_ns)
doc.xpath("//aaa").each do |node|
  puts (node > "bbb").inspect
  # => [#<Nokogiri::XML::Element:0x3f8bc3581e28 name="bbb">]
end
@flavorjones
Copy link
Member Author

I believe we can address this if #remove_namespaces! adds the document's default namespace to each node. Or else, remove the document's default namespace. Pick one.

@flavorjones
Copy link
Member Author

Node#remove_namespaces! now removes namespace declarations as well. Closed by 543901e.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant