Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6181131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:57:58+00:00 2026-05-24T00:57:58+00:00

I am using 2.1. I am reading a RSS like like one. What I

  • 0

I am using 2.1. I am reading a RSS like like one.

What I thinking is I have to change encoding? “e.g InputStream inputStream = new ByteArrayInputStream(xmlResponse.getBytes(“UTF-8″));” Or I have to set TextView Font tp a Thai font?

<item>
  <title><![CDATA[Largo Winch 2 บู๊ระห่ำเดือดกว่าเดิม]]></title>
  <author>Siritorn</author>
  <link>http://news.voicetv.co.th/entertainment/11866.html</link>
  <description><![CDATA[<p>
ภาพยนตร์แอ๊คชั่น Largo Winch 2 ยอดคนอันตรายล่าข้ามโลก ที่นำแสดงโดย โตแมร์ ซิสเลย์ และ ชารอน สโตน พร้อมเข้าฉายระเบิดความมันให้คอหนังบ้านเราได้ชมกันแล้ววันที่ 9 มิ.ย. นี้&nbsp;&nbsp;</p>]]></description>
<pubDate>Wed, 08 Jun 2011 13:11:46 +0700</pubDate>
</item>

I am reading this RSS with following code.

DataFetcher
public ArrayList fetchRSSItems(String URL){

    ArrayList<RSSItem> items = null;

    try {
        HttpGet http = new HttpGet(URL);

        String response = this.getSendRequest(http);
        if(response.length() > 0){
            DataParser parser = new DataParser();
            items  = parser.parseDataStories(response);
        }

    } catch (Exception e) {
        Log.e("Exception", "Message = "+e.toString());
        e.printStackTrace();
    }

    return items;
}

private String getSendRequest(HttpGet http) {

    try {
        DefaultHttpClient client = new DefaultHttpClient();

        HttpResponse response ;
        String stringResponse = "";

        response = client.execute(http);

        InputStream inputStream = response.getEntity().getContent();
        BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream, 2048);
        ByteArrayBuffer byteArrayBuffer = new ByteArrayBuffer(2048);

        int currentBuf = 0;
        while((currentBuf = bufferedInputStream.read()) != -1){
            byteArrayBuffer.append((byte) currentBuf);
        }

        stringResponse = new String(byteArrayBuffer.toByteArray());
        return stringResponse;
    } catch (Exception e) {
        Log.e("Exception", "Message = "+e.toString());
        e.printStackTrace();
    }
    return null;
}

Code for parser

public ArrayList<RSSItem> parseDataStories(String xmlResponse){
    ArrayList<RSSItem> itemList = new ArrayList<RSSItem>();
    try{
        InputStream inputStream = new ByteArrayInputStream(xmlResponse.getBytes("UTF-8"));

        DocumentBuilderFactory fectory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = fectory.newDocumentBuilder();
        Document document = builder.parse(inputStream);

        NodeList nodeList;
        Node childNode;

        nodeList = document.getElementsByTagName("item");

        for(int i = 0; i<nodeList.getLength() ; i++){
            childNode = nodeList.item(i);
            RSSItem item = this.parseStoryItem((Element) childNode);
            if(item != null){
                System.out.println(item.toString());
                if(item.getImagePath() != null){
                    item.setImage(AsyncImageLoader.loadImageFromUrl(item.getImagePath()));
                }
                itemList.add(item);
            }
        }

    }catch (Exception e) {
        Log.e("Exception","Message = "+e.toString());
    }catch (Error e) {
        Log.e("Error","Message = "+e.toString());
    }

    return itemList;
}

private RSSItem parseStoryItem(Element theElement) {
    RSSItem currentStory = new RSSItem();
    Node childNode;
    NodeList allChildern;

    try {
        String title = "";
        String description = "";

        childNode = theElement.getElementsByTagName("link").item(0);
        String fullStoryLink = childNode.getFirstChild().getNodeValue();
        currentStory.setFullPath(fullStoryLink);

        allChildern = theElement.getElementsByTagName("title").item(0).getChildNodes();
        for (int index = 0; index < allChildern.getLength(); index++) {
            title += allChildern.item(index).getNodeValue();
        }
        currentStory.setTitle(title);

        // Read the summary of Story
        if ((theElement.getElementsByTagName("description")).getLength() > 0) {

            allChildern = theElement.getElementsByTagName("description").item(0).getChildNodes();

            for (int index = 0; index < allChildern.getLength(); index++) {
                description += allChildern.item(index).getNodeValue();
            }
            currentStory.setDescription(description);
        }

        // Get pub date if any
        if ((theElement.getElementsByTagName("pubDate")).getLength() > 0) {

            childNode = theElement.getElementsByTagName("pubDate").item(0);
            currentStory.setDate(stringFromDateString(childNode.getFirstChild().getNodeValue()));
        }

    } catch (Exception e) {
        Log.e("Exception", "parseStoryItem Message = " + e.toString());
    } catch (Error e) {
        Log.e("Error", "parseStoryItem Message = " + e.toString());
    }

    return currentStory;
}

public static String stringFromDateString(String string) {

    String datePart = string.substring(0, 25);

    return datePart;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:58:00+00:00Added an answer on May 24, 2026 at 12:58 am

    I just use Thai supported font for TextView and its working great.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With the following file reading code: using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read,
I am thinking of using sed for reading .properties file, but was wondering if
I'm reading a rss feed using simple code: <?php $homepage = file_get_contents('http://www.forbes.com/news/index.xml'); $movies =
I'm new to php.I'm reading a RSS feed and store in my database table.
I'm reading and store a RSS feed in my database.I'm using this code <?php
I have a requirement to consume only the latest two rss feeds (using .NET)
I am reading this tutorial on fetching RSS feeds using PHP Simple XML. Reason
I am reading a Rss feed using setInterval method and displaying notification to the
I am reading a Rss feed using setInterval method and displaying notification to the
I have a WordPress xml data file encoding with utf-8. But the WordPress impoter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.