Skip to content Skip to sidebar Skip to footer

Parsing An Utf-8 Encodded Xml File

I have an XML File containing some Arabic Characters retrieved from a URL so I had to encode it in UTF-8 so it can handle such characters. XML File:

Solution 1:

You've added a BOM in your UTF-8 file. Which is bad.

Maybe you edited your file with Notepad, or maybe you should check your editor to ensure it doesn't add a BOM.

As the BOM seems to be inside the text and not at start, you also need to remove it by using the delete key around its position (it's invisible in most editors). This may have happened during a file concatenation operation.

Solution 2:

This might not be the problem, but EntityUtils.toString(httpEntity).getBytes() is using the default platform encoding. You should use EntityUtils.toString(httpEntity) as the String, no need to turn it into bytes.

Also, read this http://kunststube.net/encoding/ for useful background on what's going on.

Post a Comment for "Parsing An Utf-8 Encodded Xml File"