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 6859505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:17:30+00:00 2026-05-27T02:17:30+00:00

I want to parse a rss feed but it fails at some characters, for

  • 0

I want to parse a rss feed but it fails at some characters, for example “>” char and all before this char.

Example:

<title>[Maths I &gt; Theory] Maths I, T1.pdf: One file added.</title>

Output:

[Maths I 

This is my RSSHandler:

public class RSSHandler extends DefaultHandler {

final int state_unknown = 0;
final int state_title = 1;
final int state_description = 2;
final int state_link = 3;
final int state_pubdate = 4;
int currentState = state_unknown;

RSSFeed feed;
RSSItem item;

boolean itemFound = false;

RSSHandler(){
}

RSSFeed getFeed(){
return feed;
}

@Override
public void startDocument() throws SAXException {
// TODO Auto-generated method stub
feed = new RSSFeed();
item = new RSSItem();

}

@Override
public void endDocument() throws SAXException {
// TODO Auto-generated method stub
}

@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
// TODO Auto-generated method stub

if (localName.equalsIgnoreCase("item")){
itemFound = true;
item = new RSSItem();
currentState = state_unknown;
}
else if (localName.equalsIgnoreCase("title")){
currentState = state_title;
}
else if (localName.equalsIgnoreCase("description")){
currentState = state_description;
}
else if (localName.equalsIgnoreCase("link")){
currentState = state_link;
}
else if (localName.equalsIgnoreCase("pubdate")){
currentState = state_pubdate;
}
else{
currentState = state_unknown;
}

}

@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
// TODO Auto-generated method stub
if (localName.equalsIgnoreCase("item")){
feed.addItem(item);
}
}

@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
// TODO Auto-generated method stub

String strCharacters = new String(ch,start,length);

if (itemFound==true){
// "item" tag found, it's item's parameter
switch(currentState){
case state_title:
 item.setTitle(strCharacters);
 break;
case state_description:
 item.setDescription(strCharacters);
 break;
case state_link:
 item.setLink(strCharacters);
 break;
case state_pubdate:
 item.setPubdate(strCharacters);
 break;
default:
 break;
}
}
else{
// not "item" tag found, it's feed's parameter
switch(currentState){
case state_title:
 feed.setTitle(strCharacters);
 break;
case state_description:
 feed.setDescription(strCharacters);
 break;
case state_link:
 feed.setLink(strCharacters);
 break;
case state_pubdate:
 feed.setPubdate(strCharacters);
 break;
default:
 break;
}
}

currentState = state_unknown;
}


}
  • 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-27T02:17:31+00:00Added an answer on May 27, 2026 at 2:17 am

    Here is a slightly modified version which can parse RSS files well. I hope it helps.

    First, a State enum:

    public enum State {
    
        unknown, title, description, link, pubdate
    
    }
    

    Then the handler class:

    import org.xml.sax.Attributes;
    import org.xml.sax.SAXException;
    import org.xml.sax.helpers.DefaultHandler;
    
    public class RSSHandler extends DefaultHandler {
    
        private State currentState = State.unknown;
    
        private RSSFeed feed;
        private RSSItem item;
    
        private boolean itemFound = false;
    
        private StringBuilder tagContent;
    
        public RSSHandler() {
        }
    
        @Override
        public void startDocument() throws SAXException {
            feed = new RSSFeed();
            item = new RSSItem();
        }
    
        @Override
        public void startElement(final String uri, final String localName, 
                final String qName, final Attributes attributes)
                throws SAXException {
            currentState = State.unknown;
            tagContent = new StringBuilder();
            if (localName.equalsIgnoreCase("item")) {
                itemFound = true;
                item = new RSSItem();
                currentState = State.unknown;
            } else if (localName.equalsIgnoreCase("title")) {
                currentState = State.title;
            } else if (localName.equalsIgnoreCase("description")) {
                currentState = State.description;
            } else if (localName.equalsIgnoreCase("link")) {
                currentState = State.link;
            } else if (localName.equalsIgnoreCase("pubdate")) {
                currentState = State.pubdate;
            }
            System.out.println("new state: " + currentState);
    
        }
    
        @Override
        public void endElement(final String uri, final String localName, 
                final String qName) throws SAXException {
            if (localName.equalsIgnoreCase("item")) {
                feed.addItem(item);
            }
            if (itemFound == true) {
                // "item" tag found, it's item's parameter
                switch (currentState) {
                    case title:
                        item.setTitle(tagContent.toString());
                        break;
                    case description:
                        item.setDescription(tagContent.toString());
                        break;
                    case link:
                        item.setLink(tagContent.toString());
                        break;
                    case pubdate:
                        item.setPubdate(tagContent.toString());
                        break;
                    default:
                        break;
                }
            } else {
                // not "item" tag found, it's feed's parameter
                switch (currentState) {
                    case title:
                        feed.setTitle(tagContent.toString());
                        break;
                    case description:
                        feed.setDescription(tagContent.toString());
                        break;
                    case link:
                        feed.setLink(tagContent.toString());
                        break;
                    case pubdate:
                        feed.setPubdate(tagContent.toString());
                        break;
                    default:
                        break;
                }
            }
        }
    
        @Override
        public void characters(final char[] ch, final int start, final int length) 
                throws SAXException {
            tagContent.append(ch, start, length);
        }
    
        public RSSFeed getFeed() {
            return feed;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this feed http://feeds.bbci.co.uk/news/rss.xml and want to get all media:thumbnail entries. I.e.
I want to parse an existing RSS feed from another website with php and
Any example on how to parse/have access to simple RSS feed elements in JS?
I want to use jQuery to parse RSS feeds. Can this be done with
I want to parse an rss feed from an android application. Everything related to
Am trying to parse the RSS feed from www.ted.com/talks/rss, I can access all normal
Edit: Translated I have a RSS-feed that i want to parse. It's a podcast
I want to parse some HTML in order to find the values of some
I want to parse a web page in Groovy and extract all of the
I'm using YQL to parse some web feeds, this one in particular. SELECT *

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.