androidxml-parsingcdataandroid-xmlpullparser

While i am parsing XML , the text in CDATA Section doesn't seem regular


i am parsing xml from a website. But while parsing, the text in the CDATA section doesn't seem like a regular text. For example, the text contains ’ for the character " ' " . How can i solve this problem? How can i parse the text in CDATA Section normally ? I am using XmlPullParser. Here is my XMLParser:

List<Sozcu> sozcus;
Sozcu sozcu;
String text,text1;

public XMLParser() {
    sozcus = new ArrayList<Sozcu>();
}

public List<Sozcu> getCountries() {
    return sozcus;
}

public List<Sozcu> parse(InputStream inputStream){
    try{
       // HttpURLConnection connection =(HttpURLConnection) new URL(url).openConnection();
       // InputStream inputStream = connection.getInputStream();
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(false);
        XmlPullParser parser = factory.newPullParser();

        parser.setInput(inputStream,null);
        int eventType = parser.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT){
            String tagName = parser.getName();
            switch (eventType){
                case XmlPullParser.START_TAG:
                    if(tagName.equalsIgnoreCase("item")){
                        sozcu = new Sozcu();
                    }
                    break;
                case XmlPullParser.TEXT:
                    text = parser.getText();
                    break;
                case XmlPullParser.END_TAG:
                    if(tagName.equalsIgnoreCase("item")){
                        //countries.add(country);
                        sozcus.add(sozcu);
                    }else if(tagName.equalsIgnoreCase("description")){
                       // country.setRank(text);

                        sozcu.setDescription(text);
                    }else if(tagName.equalsIgnoreCase("link")){
                      //  country.setName(text);
                        sozcu.setLink(text);
                    }else if(tagName.equalsIgnoreCase("pubDate")){
                       // country.setPopulation(text);
                        sozcu.setDate(text);
                    }else if(tagName.equalsIgnoreCase("title")){
                        // country.setPopulation(text);
                        sozcu.setTitle(text);
                    }else{

                    }
                    break;
                default:
                    break;
            }
            eventType = parser.next();
        }
    }catch (Exception e){
        e.printStackTrace();
    }
    return sozcus;
}

Here is Xml: <description><![CDATA[Balyoz davasından yargılanan Emekli Amiral Semih Çetin, CNNTÜRK&#8217;te Ahmet Hakan&#8217;ın sunduğu Tarafsız Bölge programına konuk oldu. Çetin programda, 15 Temmuz darbe girişimiyle ilgili dikkat çeken bir iddiayı paylaştı. &#160; &#8220;FETÖ&#8217;cülerin sözde darbe konseyi, &#8216;Yurtta Sulh&#8217;ta yer alan isimler açıklanmadan darbe girişimi bitti sayılmaz. İnsanlar ancak o zaman evine dönebilir&#8221; diyen Çetin, çarpıcı açıklamalar yaptı. Yurtta [&#8230;]]]></description> PLEASE HELP ME


Solution

  • It looks html encoded, You need to html decode it.

    Html.fromHtml("YOUR STRING HERE").toString();