Coder Social home page Coder Social logo

Comments (10)

burtlo avatar burtlo commented on July 28, 2024

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.

from happymapper.

deiga avatar deiga commented on July 28, 2024

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

from happymapper.

Danicela avatar Danicela commented on July 28, 2024

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.

from happymapper.

burtlo avatar burtlo commented on July 28, 2024

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?

from happymapper.

Danicela avatar Danicela commented on July 28, 2024

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"))) ?

from happymapper.

Danicela avatar Danicela commented on July 28, 2024

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.

from happymapper.

Danicela avatar Danicela commented on July 28, 2024

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)

from happymapper.

mvz avatar mvz commented on July 28, 2024

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

from happymapper.

deiga avatar deiga commented on July 28, 2024

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

from happymapper.

mvz avatar mvz commented on July 28, 2024

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

from happymapper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.