R – How to use Turkish characters in xml

special charactersxml

I am using xml and have a problem with Turkish characters. Just like this

<Ürün></Ürün>...

I use str_replace for solution but it's not giving desired results.

What do I have to do?

Best Answer

The above XML snippet is perfectly valid, as long as you've saved the XML with the correct character encoding. The default encoding for XML, if you don't specify a different one in the <?xml declaration, is UTF-8.

If you have saved the file containing <Ürün> in a different encoding to UTF-8 — presumably Windows code page 1254 Turkish — it will not parse as UTF-8, so either add a <?xml version="1.0" encoding="windows-1254"?> declaration or, much better and more portable, simply save it as UTF-8 instead. Use ‘Save as’ in your text editor and pick out that encoding.

(If your text editor does not afford you that option, or it insists on re-loading UTF-8 files in code page 1254, get a better text editor.)