0

Parsing SharePoint RSS Feed

In an earlier post I explained how I was fetching an RSS feed from SharePoint behind an https layer using cURL and PHP. In this post I’ll show how I parsed the feed.

I’ll be using this RSS (feed.xml) to demonstrate parsing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<rss version="2.0">
  <channel>
    <item>
      <title>Google</title>
      <link>http://www.google.com</link>
      <description><![CDATA[<div><b>SharePoint Column 1:</b> Column 1 Value </div>
<div><b>SharePoint Column 2:</b> Column 2 Value</div>
<div><b>SharePoint Column 3:</b> Column 3 Value</div>
<div><b>SharePoint Column 3:</b> Column 3 Value</div>
]]></description>
      <author>Daffy Duck</author>
      <pubDate>Wed, 14 May 2012 05:00:00 GMT</pubDate>
      <guid isPermaLink="true">https://site/sites/mysite/Lists/mylist/DispForm.aspx?ID=1</guid>
    </item>
  </channel>
</rss>

The following code will pull all values from each item in the feed. This code does not have any output.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
 
$xml = simplexml_load_file("feed.xml");
 
foreach($xml->channel->item as $item)
    {
	$title = trim(addslashes($item->title));
	$link = trim(addslashes($item->link));
	$description = addslashes($item->description);
	$author = trim(addslashes($item->author));
	$pubDate = strtotime($item->pubDate); //into Unix timestamp
	$perma_link = urlencode($item->guid);
 
	//Clean up and trim description	
	$arr = explode("\n", strip_tags(substr($description, 8, strlen($description)-12)));
 
	//Loop through each column in description
	foreach($arr as $val)
	    {
		$tmp = explode(':', $val);
 
		$column_name = $tmp[0];
		$column_value = $tmp[1];
	     }
     }
 
?>

Norbert Krupa

Technical Consultant

Leave a Reply

Your email address will not be published.