Fixing the libxml-ruby gem error: uninitialized constant XML (NameError)
August 1st, 2008
I found the highly recommended libxml-ruby gem but was having a lot of trouble getting my sample code below to work
1 2 3 4 | require 'libxml' doc = XML::Document.file('http://search.twitter.com/search.atom?q=obama') root = doc.root puts "Root element name: #{root.name}" |
I kept getting this error
uninitialized constant XML (NameError)
on line 2 where I used “XML::”
After combing through the internets for an answer, I found it.
Just change
require 'libxml'
to
require 'xml/libxml'
and everything should go swimmingly.
PS: The code above should simply output ‘feed’
Entry Filed under: ruby

Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">
Trackback this post | Subscribe to the comments via RSS Feed