Introduction and Quick Start

Introduction and Quick Start – Overview of XML_Feed_Parser


XML_Feed_Parser provides a generic interface to a number of the most popular XML-based syndication formats (Atom, RSS1, RSS2, etc). In order to focus on its core competencies, it does not provide any HTTP or feed creation features, but instead parses a wide range of formats quickly and simply.

Presuming the XML for a feed is stored in the variable $xml_source, the simplest way to create an instance of the parser is:

try {
$feed = new XML_Feed_Parser($xml_source);
} catch (
XML_Feed_Parser_Exception $e) {
'Feed invalid: ' $e->getMessage());

The constructor accepts a number of parameters, as follows:

/* The file you wish to parse */
$source 'my_source.xml';

/* Where Relax NG is available, we can force validation of the feed */
$validate true;

/* Whether or not to suppress non-fatal warnings */
$suppress_warnings false;

/* If the feed is not valid XML and the tidy extension is installed we can
 * attempt to use it to fix the feed */
$use_tidy true;

$feed = new XML_Feed_Parser($source$validate$suppress_warnings$use_tidy);

Once you have an instance of the parser you can extract feed-level data by querying it directly. eg.


You can also access elements by iterating over the feed, or directly by offset or id.

foreach ($feed as $entry) {
$entry->title "\n";

$first_entry $feed->getEntryByOffset(0);

$particular_entry $feed->getEntryById('');
XML_Feed_Parser (Previous) Handling extensions with XML_Feed_Parser (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.