Click here to Skip to main content
15,885,992 members
Articles / Desktop Programming / WTL

RSS Reader Plug-in for Internet Explorer

Rate me:
Please Sign up or sign in to vote.
5.00/5 (12 votes)
16 Jul 2007CPOL4 min read 317.3K   1.3K   32  
This is a toolbar for the Internet Explorer which shows information from RSS taken from the Internet.
/*
	Project		: RSS Reader plugin for Internet Explorer
	File Name	: RRPRssParser.cpp
	Date		: 
	Purpose		: It is the parser for the rss file. 
	Note		: 
	Send comments 
	or Bugs to	: prafulla_t@users.sourceforge.net
*/
#include "StdAfx.h"
#include "RRPRssParser.h"

#include <iostream>
#include <string>

RRPRssParser::RRPRssParser(const char *nameOfFile) {
	doc = new TiXmlDocument(nameOfFile);
	errorCode = doc->LoadFile();
	//Store it in private variable,for future reference
	fileName = new char[strlen(nameOfFile) + 1];
	strcpy(fileName,nameOfFile);
}

RRPRssParser::~RRPRssParser(void) {
	if(fileName)
		delete fileName;
	if(doc)
		delete doc;
	int n = rssItemVector.size();
	for(int i = 0; i< n;i++)
		delete rssItemVector[i];
}

//Parses the RSS file,and fills up all the required structurs  
//It SHOULD be called before getting the reference of RRPRssItemIterator
void RRPRssParser::parse() {
	TiXmlElement *rootElement = doc->FirstChildElement();
	TiXmlElement *itemElement;
	TiXmlElement *titleElement,*linkElement,*descElement;
	RRPRssItem *rssItem = NULL;

	if(rootElement) {
		rootElement = doc->FirstChildElement();
		if(!rootElement)
			return;
		rootElement = rootElement->FirstChildElement();
		if(!rootElement)
			return;
		//Now getting Item 
		itemElement = rootElement->FirstChildElement("item"); 
		while(itemElement) {
			titleElement = itemElement->FirstChildElement("title");
			linkElement = itemElement->FirstChildElement("link");
			if(!linkElement)
				linkElement = itemElement->FirstChildElement("guid");
			descElement = itemElement->FirstChildElement("description");
/*			pubElement =  itemElement->FirstChildElement("pubDate");
			if(!pubElement)
				return;*/
			rssItem = new RRPRssItem();

			if(titleElement && (titleElement->GetText())) 
					rssItem->setTitle(titleElement->GetText())			;
			else 
				rssItem->setTitle("No Title,Have a look at Description!!");

			if(linkElement && (linkElement->GetText())) 
				rssItem->setLink(linkElement->GetText());
			else
				rssItem->setLink("No Link");
			
			if(descElement && (descElement->GetText()))
				rssItem->setDescription(descElement->GetText());
			else
				rssItem->setDescription("No Description");
			
/*			if(pubElement)
				std::cout << pubElement->ValueTStr().c_str() << " :: " <<  pubElement->GetText() << std::endl;
			else
				std::cout << "No PubDate" << std::endl;*/
			rssItemVector.push_back(rssItem);
			itemElement = itemElement->NextSiblingElement();
		}

		}

}

//Returns true if there is no error
BOOL RRPRssParser::isError() {
	return !errorCode;
}

//Returns Error String if there is Error and "No Error" string otherwise
const char* RRPRssParser::getErrorString() {
	if(errorCode)
		return "No Error";
	return doc->ErrorDesc();
}

BOOL RRPRssParser::hasNext() {
	return (index+1) < (rssItemVector.size());
	
}

//Returns Current RssItem
RRPRssItem* RRPRssParser::getItem() {
	return rssItemVector[++index];
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
Quote : "Life is all about solving problems and enjoying their solutions !! "

Comments and Discussions