You are here

function common_syndication_parser_parse in Feeds 7.2

Same name and namespace in other branches
  1. 8.2 libraries/common_syndication_parser.inc \common_syndication_parser_parse()
  2. 6 libraries/common_syndication_parser.inc \common_syndication_parser_parse()
  3. 7 libraries/common_syndication_parser.inc \common_syndication_parser_parse()

Parse the feed into a data structure.

Parameters

string $string: The feed object (contains the URL or the parsed XML structure).

Return value

array|false The structured datas extracted from the feed or FALSE in case of failures.

6 calls to common_syndication_parser_parse()
CommonSyndicationParserTestCase::_testAtomEntriesWithoutBaseUrl in tests/common_syndication_parser.test
Tests if the base url is prepended for entries without base url.
CommonSyndicationParserTestCase::_testAtomGeoRSS in tests/common_syndication_parser.test
Test Geo RSS in Atom feed.
CommonSyndicationParserTestCase::_testAtomGeoRSSWithoutAuthor in tests/common_syndication_parser.test
Tests parsing an Atom feed without an author.
CommonSyndicationParserTestCase::_testRSS10 in tests/common_syndication_parser.test
Test RSS 1.0.
CommonSyndicationParserTestCase::_testRSS2 in tests/common_syndication_parser.test
Test RSS 2.

... See full list

File

libraries/common_syndication_parser.inc, line 22
Downloading and parsing functions for Common Syndication Parser. Pillaged from FeedAPI common syndication parser.

Code

function common_syndication_parser_parse($string) {

  // SimpleXML can only deal with XML declaration at the start of the document,
  // so remove any surrounding whitespace.
  $string = trim($string);
  @($xml = simplexml_load_string($string, NULL, LIBXML_NOERROR | LIBXML_NOWARNING | LIBXML_NOCDATA));

  // Got a malformed XML.
  if ($xml === FALSE || is_null($xml)) {
    return FALSE;
  }
  $feed_type = _parser_common_syndication_feed_format_detect($xml);
  if ($feed_type == "atom1.0") {
    return _parser_common_syndication_atom10_parse($xml);
  }
  if ($feed_type == "RSS2.0" || $feed_type == "RSS0.91" || $feed_type == "RSS0.92") {
    return _parser_common_syndication_RSS20_parse($xml);
  }
  if ($feed_type == "RDF") {
    return _parser_common_syndication_RDF10_parse($xml);
  }
  return FALSE;
}