Comments (10)
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.
Nokogiri supports giving an encoding to it http://www.nokogiri.org/tutorials/parsing_an_html_xml_document.html
from happymapper.
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.
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.
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.
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.
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.
@deiga what encoding did the original XML in your example have?
from happymapper.
@mvz unfortuantely I have no idea after 3 years of opening this issue :)
from happymapper.
@deiga that was to be expected :-). Thanks for responding, anyway.
from happymapper.
Related Issues (20)
- How to access `wrap` child elements HOT 1
- XML parse issue HOT 1
- Malformed XML while using to_xml HOT 2
- Deprecate positional optional arguments for #to_xml
- Better support for inheritance
- Register Namespace Ordering HOT 2
- `BigDecimal` not working with Ruby 2.7+ because `#new` was removed HOT 3
- JRuby NAMESPACE_ERR when root node has a namespace prefix HOT 3
- to_xml: How to Add a Namespace to the Root Element Only HOT 2
- CamelCase elements always nil HOT 2
- Namespace confusion HOT 3
- Parsing nil values in XML causing ArgumentError HOT 2
- Update gemspec HOT 1
- Make happymapper specs run warning-free
- Run specs on Travis CI HOT 1
- Document options and their relations better HOT 1
- Contact Github to turn this fork into its own project. HOT 5
- wrap doesn't work for custom getter HOT 3
- Parse takes a block, only used if :in_groups_of is passed?
- Warn if multiple elements found unexpectedly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from happymapper.