Uninitialized constant XML::Document

Hi All,

I have installed “libxml-ruby” gem on my ruby instllation. while trying
to create xml document with ruby progam in Rad Rails am getting error
like “uninitialized constant XML::Document (NameError)”
do i need to config any thing else in environment.rb file

Thanks in advance
Chinna.

Hi

In config/environment.rb you have to add

config.gem “libxml-ruby”, :lib=>“xml/libxml”, :version=>"=versionnumber"

Sijo

Sijo k g wrote:

Hi

In config/environment.rb you have to add

config.gem “libxml-ruby”, :lib=>“xml/libxml”, :version=>"=versionnumber"

Sijo

Hi Sijo,

  Thank you very much for your quick response. I have updated 

config/environment.rb file ad u suggested as follows
config.gem “libxml-ruby”, :lib=>“xml/libxml”, :version=>“1.1.3” .
but am getting same error. Are there any things am missing, can you pls
suggest me.

Regards
Chinna.

Hi Sijo,

here is the code can you suggest me where is going wrong.More over i am
not working on the server. I am just creating simple example on RadRails
IDE.

require ‘xml/libxml’

doc = XML::Document.new()
doc.root = XML::Node.new(‘root_node’)
doc.root << XML::Node.new(‘elem1’)
puts doc

Chinna.

Hi

Restart the server after added this. And even if the problem exists,
paste the code

Sijo

Hi

I am just creating simple example on RadRails IDE.

This I didnot understand. Anyway if you are working from konsole 

before
require ‘xml/libxml’ you have to write
require ‘rubygems’

Try this from konsole

Sijo

Hi Sijo,

What i mean is, i created a simple ruby class as follows . And in that
class i am trying to crate xml document by ‘xml/libxml’ lib. Even adding
require ‘rubygems’ also my problum has not solved. I think the libxml
gem is not installed properly. How can i check whether the gem is
installed properly or not.

class FirstRubyProgram
require ‘xml/libxml’
require ‘rubygems’

doc = XML::Document.new()
doc.root = XML::Node.new(‘root_node’)
doc.root << XML::Node.new(‘elem1’)
puts doc
end

Hi

. How can i check whether the gem is installed properly or not.

You can check with
gem list

class FirstRubyProgram
require ‘xml/libxml’
require ‘rubygems’

doc = XML::Document.new()
doc.root = XML::Node.new(‘root_node’)
doc.root << XML::Node.new(‘elem1’)
puts doc
end

The above should be

class FirstRubyProgram
require ‘rubygems’
require ‘xml/libxml’

doc = XML::Document.new()
doc.root = XML::Node.new(‘root_node’)
doc.root << XML::Node.new(‘elem1’)
puts doc
end

Sijo

Hi Sijo/Rick,

Thanq very much for your response and finally i got the result with the
following stuff.

require ‘libxml’
document = LibXML::XML::Document.new

Thanq
Chinna

Direct from the libxml-ruby rdocs:


The libxml gem provides Ruby language bindings for GNOME’s Libxml2 XML
toolkit. To get started you may:

require ‘xml’
document = XML::Document.new

However, when creating an application or library you plan to
redistribute, it is best to not add the LibXML module to the global
namespace, in which case you can either write your code like this:

require ‘libxml’
document = LibXML::XML::Document.new

You should probably take some time to get familiar with gem
documentation.

See: http://docs.rubygems.org/read/chapter/2#page10

On Nov 12, 6:22 am, Chinna Gogulapati <rails-mailing-l…@andreas-