Problems parsing Spanish characters (á, é, í, ó, ú) from an XML response

I am developing a Java application that calls PHP from the Internet, which gives me an XML response.

The answer contains this word: "Próximo", but when I parse the XML nodes and get the response into the String variable, I get the word like this: "Pr & oacute; ximo".

How can i solve this?

+1
source share
3 answers

Perhaps you use a different encoding in your Java application and then encode a PHP script. Try setting the encoding of your stream, for example, for example

URL oracle = new URL("http://www.yourpage.com/"); URLConnection yc = oracle.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader( yc.getInputStream(),"utf-8"));//<-- here you set encoding //to the same as in your PHP String inputLine; while ((inputLine = in.readLine()) != null) System.out.println(inputLine); 
0
source

I found a solution to this problem ... When parsing, use the format "ISO-8859-1" and use the Html.fromHtml (string) method, storing your values ​​in a bean. Where "string" is the value inside each XML response tag.

0
source

Source: https://habr.com/ru/post/921084/


All Articles