[Drupal] How to create a new parser in Feed API module
The feedAPI module is a famous one for processing custom feeds in different formats like rss/Atom, csv, iCal etc. Now the feedAPI has upgraded to the "feeds",which have more features and easy to use and customize. However still a lot of Drupal 6 sites uses the feedAPI module for handling external feeds. Let us see how a new parser could be created in feed API module.
The module provides a lot of third-party parsers to parse each kind of feed types, some are,
- The RSS/Atom feeds could be parsed using the Common Syndication Parser (part of FeedAPI).
- The iCal feeds could be parsed with the iCal parser.
- The CSV files could be aggregated with CSV parser.
- The KML feeds could be parsed with KML parser
But the feedAPI module implemented each of these parsers as separate modules, so if you need to create a new parser you need create a new module for it. There will be multiple situations when you need to implement a new parser, like when you need to process some custom feed content with custom tags, or need to implement a parser for some new type of feeds for which a parser is not available. Anyway I will explain some basics for creating a new one.
Creating a help case
This is first step, feels like some weird way to define a new parser, however you need to implement the path 'feedapi/full_name' and need to return the name of the new feed parser here. Which means a single module can only implement a single parser.
Implement the hook_feedapi_feed
Now you need to implement the hook "hook_feedapi_feed" to implement the basic working of your feed parser. Here you have to define the 3 values of the operations($op) parameter, they are,
Here you can define the types of feeds your parser is going to deal with.
Here you can actually parse the feed object you received, you can depend on the PHP's simplexml functions to convert the xml file into a feed object. All the operations related to parsing the fed object could be done here.
In this operation you can check whether the incoming feed is compatible for your parser or not.
If the parser provides any settings that are specific for the feed it handles, you could create a settings form by implementing this hook. If this hook implemented then at the time of parser choice for a particular node the settings form displayed.
If no settings form created for a particular parser then the selected parser would not show upon the node edit page.