Skip to main content

Creating a custom parser

The component does support the major formats of CSV files. Using the mapping in feed configuration any CSV file (with a header row) should work. Problem might be that the 'description' field has a different name, and there is no mapping for the description. This can be solved easily using a callback function.


If the data is only available in xml format the existing parsers will  probably not work. Still you might give it a try many feeds use 'item' or 'product' as tag so just try the existing parsers.


Otherwise the solution is to add you own parser. The component allows to add two custom parsers:


Create a file in administrator/components/com_datafeeds/cron

In this file you can put your own parser. Most basic duplicating the existing parser:

Class MyXMLParser extends TradetrackerRSS{

$feed_parsers['MyXMLParser']='My Own Parser';

Next step would be to copy the relevant functions from the TradetrackerRSS class (start element and end element) and alter the code.

On the page about 'adding share a sale' feeds you can find an example of a custom parser.

Example basic parser

The parser below can be used for simple xml structures without tree's or attributes.

class CarRSS extends BasicRSS{

$feed_parsers['CarRSS']='Car Parser';

Copy the code into the file administrator/components/com_datafeeds/cron/ and modify the code as desired. The item_tag is the main product container in the XML file. As you can see in the example data below each item is wrapped in <car>...</car> 

<?xml version="1.0" encoding="ISO-8859-1"?>
<modeldescription>1.8 T Avant, Proline</modeldescription>