Coder Social home page Coder Social logo

openrssparser's Introduction

Welcome to Open RSS Parser

Open RSS Parser, as its name says, is an RSS/Atom feeds parser. It aims to be light, easy to use, and doesn't rely on external libraries. Created on august 23th, 2013, it's obviously extremely small and not usable in production yet.

Build Status

Current Version

For now it supports

  • Atom feeds as described in the RFC4287 specification
  • RSS 2 feeds as described in Harvard specification

All cases are not yet implemented but most of them are; And the code is voluntarily very simple. There are no errors handling and no optimizations.

HowTo

You'll have to first declare your source:

  • If it's a local feed file use declareFile(filePath) method
  • If it's a remote feed use declareURL(url) method

Then, there are two ways to use Open Rss Parser :

  1. Let the parser do all the work and returns you a Feed object containing all the data in the atom/rss file
  2. Iterate yourself on the feed to get the elements (one header and one or many entries) (be sure to close the parser at the end)

Example 1

OpenRssParser myParser = new OpenRssParser();
myParser.declareFile(feedPath); // Or myParser.declareURL(feedUrl);
Feed feed = myParser.getFeed(); // The parser closes itself before returning the Feed object

Example 2

OpenRssParser myParser = new OpenRssParser();
myParser.declareFile(feedPath); // Or myParser.declareURL(feedUrl);
Header header = myParser.getHeader();
while (myParser.hasEntry()) {
  Entry entry = myParser.nextEntry();
  entry.getTitle();
}
myParser.close();

The difference between these two ways is that the first one reads and parses all the file, create all the objects and returns them all at once in a Feed instance, but the second one is like a cursor: it reads the elements one by one and return them on the go. So the second way is faster than the first one. If you need to get all the data of an atom/rss file, you may need to use the first method, if you need to get only one or two entries of a feed you should use the second way (don't forget to getHeader() first and close() at the end). Both ways take a few milliseconds to execute on regular feeds (a dozens of entries).

You can get the type of your feed using this method

myParser.getFeedType(); // Returns either FeedType.ATOM or FeedType.RSS2

The Header and Entry objects are two unifications between Atom and Rss2 models. Some informations that are not widely used might have been lost in the unification process. If you want to use them anyway, the real objects are stored inside these ones. So you can use the getInitial() method to get them:

header.getInitial(); // Returns an instance of AtomSource or Rss2Header depending on the value of FeedType
entry.getInitial(); // Returns an instance of AtomEntry or Rss2Item depending on the value of FeedType

More examples in the samples package.

Wanna help ?

Feel free to give suggestions, corrections. You can open issues and pull requests are welcome.

openrssparser's People

Contributors

iamfiras avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.