escape does not work properly with international characters. How should I handle those ?
Tiya Kd wrote:escape does not work properly with international characters.
I am encoding the XML using escape function and UTF-8 and passing it over. The receiver's end when they try to decode it, get a marshalling error. I do not have much stuff to describe because at my side I am good. But have to solve the problem.
Bear Bibeault, I am not trying to keep the error message secret. As I said earlier I do not have much information about the error message because it is not happening at my side i.e sender's side. I am not the receiver of the information. All I know is the receiver expects me to send a data xml with UTF-8 encoding.
When I send the first name as Melviñ, the value being passed for ñ is %F1, whereas the receiver (who is using UTF-8 encoding) expects it to be %C3%B1 for ñ.
At sender's end, I am using an ecape function on the xml being passed along with UTF-8 encoding.
SO the question is : what should I do in order to send the value for ñ as %C3%B1 and not %F1 ?
"Unicode characters \u0000 to \u00ff are replaced with the %xx escape sequence, and all other Unicode characters are replaced with the %uxxxx sequence."
That's what you say you don't want, and based on your description I'd say you are correct in not wanting that.
It says this about the encodeURI() function:
"Any other characters in URI are replaced by converting each character to its UTF-8 encoding and then encoding each of the resulting one, two, or three bytes with a hexadecimal escape sequence of the form %xx."
That sounds a lot more like what you want. So why didn't you take my advice and try switching from escape() to encodeURI()?
encodeURI works well to solve my problem but encodeURI does not work well if there is an apostrophe in my XML (eg. <lastName>O'Hare</lastName>).
please suggest something that can work well with both - special characters as well as international characters.