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

No .keys method on node_name = 'html' #324

Closed
mfn opened this issue Aug 2, 2010 · 3 comments
Closed

No .keys method on node_name = 'html' #324

mfn opened this issue Aug 2, 2010 · 3 comments

Comments

@mfn
Copy link

mfn commented Aug 2, 2010

Hi,

I don't know if its supposed to work or not (I'm rather new to ruby) but when calling .keys on the tag it throws an error:

$ ruby -r nokogiri -e 'Nokogiri::HTML("<html></html>").traverse { |n| puts n.node_name ; puts n.keys };'
html
/opt/ruby-1.9.1-p378/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1/lib/nokogiri/xml/node.rb:397:in `keys': undefined local variable or method `attribute_nodes' for #<Nokogiri::XML::DTD:0x00000000976888> (NameError)
        from -e:1:in `block in <main>'
        from /opt/ruby-1.9.1-p378/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1/lib/nokogiri/xml/node.rb:595:in `call'
        from /opt/ruby-1.9.1-p378/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1/lib/nokogiri/xml/node.rb:595:in `traverse'
        from /opt/ruby-1.9.1-p378/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1/lib/nokogiri/xml/node.rb:594:in `block in traverse'
        from /opt/ruby-1.9.1-p378/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1/lib/nokogiri/xml/node_set.rb:239:in `block in each'
        from /opt/ruby-1.9.1-p378/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1/lib/nokogiri/xml/node_set.rb:238:in `upto'
        from /opt/ruby-1.9.1-p378/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1/lib/nokogiri/xml/node_set.rb:238:in `each'
        from /opt/ruby-1.9.1-p378/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.3.1/lib/nokogiri/xml/node.rb:594:in `traverse'
        from -e:1:in `<main>'

The error says that the node is of type Nokogiri::XML::DTD , so I looked at http://nokogiri.org/Nokogiri/XML/DTD.html and followed the link to http://nokogiri.org/Nokogiri/XML/Node.html where documents there's a keys method.

But I also realized that calling .attributes on the HTML node returns nil.

@flavorjones
Copy link
Member

Hi. I think what you probably want to do is to start from the root node of the document:

Nokogiri::HTML("<html></html>").root.traverse ...

The DTD doesn't have attributes in the sense that a HTML/XML element does. The bug here is that Nokogiri::XML::DTD has a keys method. That will be removed.

@flavorjones
Copy link
Member

Hum, I actually take that back. The attributes are implemented differently by libxml, and so will require some coding.

@flavorjones
Copy link
Member

XML::DTD attribute methods act more like XML::Node attribute methods. Closed by 227d696.

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

2 participants