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

Is there a way to specify which encoding to use when mapping? #53

Open
deiga opened this issue Sep 5, 2014 · 10 comments · May be fixed by #202
Open

Is there a way to specify which encoding to use when mapping? #53

deiga opened this issue Sep 5, 2014 · 10 comments · May be fixed by #202
Labels

Comments

@deiga
Copy link

deiga commented Sep 5, 2014

I get messed up unicode characters when parsing, ie. Liiketoimintayksikkö => Liiketoimintayksikk\303\266

@burtlo
Copy link
Collaborator

burtlo commented Nov 18, 2014

That's not something I ever considered. It would be a great addition to the library. If it is an option that can get to Nokogiri, it's an option this library could support.

@deiga
Copy link
Author

deiga commented Nov 19, 2014

Nokogiri supports giving an encoding to it http://www.nokogiri.org/tutorials/parsing_an_html_xml_document.html

@Danicela
Copy link

Danicela commented Jul 2, 2015

Hi,

When I make a node.to_xml, the XML produced is not in UTF-8, then french accents are corrupted. (assuming node is an instance of a class 'Node include HappyMapper')

I tried various things but the happymapper to_xml seems to be different from nokogiri to_xml and doesn't accept arguments which set encoding.

How do I select the encoding for happymapper marshalling (objects -> xml) ?

Thank you.

@burtlo
Copy link
Collaborator

burtlo commented Jul 2, 2015

Here are the current set of options you pass to to_xml. I think that this could easily be updated to provide support to send off parameters to Nokogiri.

@Danicela how do you think you would want to add the Nokogiri options to that method?

@Danicela
Copy link

Danicela commented Jul 2, 2015

I'm not sure to understand how to do it, I'm beginner in Ruby.

It would be something like node.to_xml(:builder => new builder(encode("UTF8"))) ?

@Danicela
Copy link

Danicela commented Jul 6, 2015

I tried :

nokogiriBuilder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8')
file.write(node.to_xml(nokogiriBuilder, nil, nil))

But it writes "#Nokogiri::XML::Builder:0x3cce640".

Then I came back to :
file.write(node.to_xml)

And I modified happymapper.rb at line 505 :
builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') instead of :
builder = Nokogiri::XML::Builder.new

And then it worked.

Now... I have to find a way to make the same thing without modifying happymapper.rb.

@Danicela
Copy link

Danicela commented Nov 3, 2015

I got help on this subject, here is the line that doesn't need any change in the gem code :

file.write(node.to_xml(Nokogiri::XML::Builder.new(encoding: 'UTF-8'), nil, nil).to_xml)

@mvz
Copy link
Owner

mvz commented Dec 31, 2017

@deiga what encoding did the original XML in your example have?

@mvz mvz added the bug label Dec 31, 2017
@deiga
Copy link
Author

deiga commented Jan 3, 2018

@mvz unfortuantely I have no idea after 3 years of opening this issue :)

@mvz
Copy link
Owner

mvz commented Jan 3, 2018

@deiga that was to be expected :-). Thanks for responding, anyway.

amseledka added a commit to amseledka/happymapper that referenced this issue Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants