Empact / roxml

ROXML is a module for binding Ruby classes to XML. It supports custom mapping and bidirectional marshalling between Ruby and XML using annotation-style class methods, via Nokogiri or LibXML.
http://roxml.rubyforge.org/
MIT License
223 stars 176 forks source link

ROXML encoding #15

Closed strny closed 14 years ago

strny commented 15 years ago

I've created this simple class: class TestResult include ROXML xml_accessor :message end

My controller code looks like this: def test res = TestResult.new res.message = "Žlutý kůň" respond_to do |format| format.xml {render :xml=>res.to_xml} end end Output in a browser is (UTF-8): <testresult>

Žlutý kůň
</testresult\>

Output should be:

Žlutý kůňˆ

I am using libxml. Thanks. Pavel

konung commented 15 years ago

Hi, Pavel. Have you tried another lib. I'm having no problems with nokogiri and / or rexml as my xml libs and Russian stored in utf-8 in my mysql

konung commented 15 years ago

Pavel, I just confirmed on my machine. It looks like you are using polish, hungarian or chek? Right? I tried with russian on a windows machine. Using nokogiri as my backend lib.

My test:

require 'roxml' 
class TestResult
    include ROXML
    xml_accessor :message
end

def test
    res = TestResult.new
    res.message = "sadfk одловыа jjklsd " #random russian  and english charecters
    res.to_xml
end

@test_string = test
@utf_xml = @test_string.serialize(:encoding => 'UTF-8', :save_with => :as_xml)

File.open("test.xml","w") do |f| 
    f << @utf_xml
end

This produces an xml file - that is properly formatted and encoded. However if you run the same in irb - and take a look that the internal of that xml element - you will see that it actually holds mapped values corresponding to utf values of those characters. I hope that makes sense. :-)

strny commented 15 years ago

Thank you for your answer. I found that I used old version of ROXML (2.5.3), new version is working well.

Empact commented 14 years ago

Glad you folks worked this out. I've got tests on this now (if I didn't in the past) to ensure roxml doesn't regress in the future.

konung commented 14 years ago

Glad to help :-) You created a great library!