7.3. XParser

News aggregation sites using syndication formats are gaining popularity as the formats become more widely used. Many sites use server-side logic to parse RSS and Atom feeds, displaying them in some sort of user-friendly format. However, it may be necessary to perform the same functions on the client-side using JavaScript. This is where XParser comes in.

XParser is a JavaScript library that parses RSS and Atom feeds into JavaScript objects, making the feed's data easy to access in web applications. Its primary goal is to provide an interface for JavaScript developers to quickly access a feed's most important elements. The code is object–oriented, broken into abstract classes that the Atom- and RSS-specific classes inherit from. Such a design allows the different feed types to be parsed according to their specific differences while leaving room for extensions. This section explains how the XParser code is designed and implemented.

7.3.1. The xparser Namespace

XParser begins with the xparser namespace. A namespace contains the library's code in one simple package and protects the contained code from external naming conflicts. Of course, JavaScript does not implement an official namespace construct; however, you can simulate the behavior of a namespace quite easily with a simple object.

var xparser = {};

This code defines the xparser object using object literal notation. It is this object that holds data, methods, and classes for XParser.

Because the script deals with ...

Get Professional Ajax, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.