Rails Sending Non ASCII in XML
during working on a project @ MashLtd , I faced a problem which nearly made me cry :) :), my task was to send XML containing Arabic characters.
the Good news is that Rails sends all XML data in Utf-8 encoding by default but
The bad news is that Rails converts any non ASCII characters to a format called XMl decimal entity format
so every time you write the following code
render @object.to_xml
you find this format showing up
I searched online but unfortnetly i didn't find a way to solve this problem
so i had to do it by myself :)
The problem is caused from the gems called Builder as it has a method called escape under XMLBase class this method does the following
private
def _escape(text)
text.to_xs
end
(dot)to_xs is the method which converts the data to entity format
So all what you have to do is just override the method and remove (dot)to_xs
you have to create a file in the intializers and name it for example patch_for_xml
then add in it the following code
class Builder::XmlBase < BlankSlate
private
def _escape(text)
text
end
end
this is called monkey patching , it is used to override classes you could use any others if you like












