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

  • Home
  • SEARCH
  • 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 674243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:41:04+00:00 2026-05-14T00:41:04+00:00

I wanted to parse the xml feed and display as links in my Blackberry

  • 0

I wanted to parse the xml feed and display as links in my Blackberry application.

After googling it, i found out that i have to use SAX parser. I have not found any good example.

For example if i want to parse the news rss feed from bbc.co.uk. How to do it. How to extract images from rss feed.

Please Help, Advise, and Guide me.
SIA
Thanks

  • 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-14T00:41:04+00:00Added an answer on May 14, 2026 at 12:41 am

    Lets say its twitter rss xml we are talking about:

    <?xml version="1.0" encoding="UTF-8"?>
    <rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" 
      xmlns:georss="http://www.georss.org/georss">
      <channel>
        <title>Twitter / LPProjekt</title>
        <link>http://twitter.com/LPProjekt</link>
        <atom:link type="application/rss+xml" 
          href="http://twitter.com/statuses/user_timeline/27756405.rss" rel="self"/>
        <description>Twitter updates from Linkin Park Projekt</description>
        <language>en-us</language>
        <ttl>40</ttl>
      <item>
        <title>LPProjekt: the instrumental from &quot;what ive done&quot;</title>
        <description>LPProjekt: the instrumental from &quot;</description>
        <pubDate>Sun, 07 Feb 2010 23:34:26 +0000</pubDate>
        <guid>http://twitter.com/LPProjekt/statuses/8784251683</guid>
        <link>http://twitter.com/LPProjekt/statuses/8784251683</link>
      </item>
    ..
      </channel>
    </rss>
    

    First of all implement handler for your xml, to take < title > and < link > value from < item > only:

    class RSSHandler extends DefaultHandler {
        boolean isItem = false;
        boolean isTitle = false;
        boolean isLink = false;
        String[] title = new String[] {};
        String[] link = new String[] {};
        String value = "";
    
        public void startElement(String uri, String localName, String name,
                Attributes attributes) throws SAXException {
            if (!isItem) {
                if (name.equalsIgnoreCase("item"))
                    isItem = true;
            } else {
                if (name.equalsIgnoreCase("title"))
                    isTitle = true;
                if (name.equalsIgnoreCase("link"))
                    isLink = true;
            }
        }
    
        public void characters(char[] ch, int start, int length)
                throws SAXException {
            if (isTitle || isLink)
                value = value.concat(new String(ch, start, length));
        }
    
        public void endElement(String uri, String localName, String name)
                throws SAXException {
            if (isItem && name.equalsIgnoreCase("item"))
                isItem = false;
            if (isTitle && name.equalsIgnoreCase("title")) {
                isTitle = false;
                Arrays.add(title, value);
                value = "";
            }
            if (isLink && name.equalsIgnoreCase("link")) {
                isLink = false;
                Arrays.add(link, value);
                value = "";
            }
        }
    }
    

    Now, to use it, get InputStream from HttpConnection and put it all in SAXParser.parse:

    static String[][] getURLFromRSS(String url) {
            InputStream is = null;
            HttpConnection connection = null;
            RSSHandler rssHandler = new RSSHandler();
            try {
                connection = (HttpConnection) Connector.open(url);
                is = connection.openInputStream();
                try {
                    SAXParser parser = SAXParserFactory.newInstance()
                            .newSAXParser();
                    parser.parse(is, rssHandler);
                } catch (ParserConfigurationException e) {
                    e.printStackTrace();
                } catch (SAXException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    if (is != null)
                        is.close();
                    if (connection != null)
                        connection.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            String[][] result = new String[2][];
            result[0] = rssHandler.title;
            result[1] = rssHandler.link;
            return result;
        }
    

    Now use custom LabelField as a link field:

    class LinkLabel extends LabelField
    {
        String mUrl = "";
        public LinkLabel(String title, String url) {
            super(title, FOCUSABLE);
            mUrl = url;
        }
        protected boolean navigationClick(int status, int time) {
            Browser.getDefaultSession().displayPage(mUrl);
            return true;
        }
    }
    

    Sample of use:

    public Scr() {
        String rssUrl = "http://twitter.com/statuses/user_timeline/27756405.rss";
        String[][] urlData = getURLFromRSS(rssUrl);
        for (int i = 0; i < urlData.length; i++) {
            String title = urlData[0][i];
            String url = urlData[1][i];
            add(new LinkLabel(title, url));
        }
    }
    

    alt text http://img215.imageshack.us/img215/7583/rssurl.jpg

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

Sidebar

Related Questions

I have a hash that i wanted to parse to XML using SimpleXML but
I wanted to parse a text file that contains unstructured text. I need to
I've just started using DOM and wanted to parse an Android XML layout file
I have a LINQ query from an XML file. I am filtering out certain
I have XML I'm trying to parse and get the status of each of
I have a scenario where I wanted to load XML into SQL Server. What
So I have 0.5MB XML file with data for my iPhone application. It's all
I'm trying to parse an XML file, that file contains strings and integers. So
I have an XML data source that has HTML & CSS formatted data contained
Below is my XML. I wanted to parse this using XSL. What I want

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.