Hi all!
I have problems with setting encoding for an xml file. I want to produce
an
xml file which starts with
I tried the following code, but it gives initialized constant error when
I
try to set up document.encoding.
require ‘xml’
d = XML::Document.new()
#d.encoding = XML::Encoding::UTF_8
#=> uninitialized constant LibXML::XML::Encoding (NameError)
d.root = XML::Node.new(‘node’)
d.root << “Some info”
d.save(‘test.xml’, true)
produces:
<?xml version="1.0"?>Some info
I tried to set encoding when saving the document, as shown in
documentation,
but without luck.
#d.save(‘test.xml’, :indent => true, :encoding => ‘UTF-8’)
#=>The second parameter (format) must be true or false (ArgumentError)
#d.save(‘test.xml’, :indent => true, :encoding => XML::Encoding::UTF_8)
#=> The second parameter (format) must be true or false (ArgumentError)
I checked ruby-libxml bug tracker and such bug has not been reported. So
I
am wondering if I am doing something wrong, or its a bug.
Thanks,
Diana