Reading XML RSS Feed

OK now that we have all the content… We are ready to display it…
But before that we should check what way is the XML document structured…
For that paste the $url string in the browser and you’ll see something like this

<!-- Copyright (C) 2000-2004 - Developer Shed, Inc. -->
<rss version="2.0">
  <channel>
    <title>Dev Shed - The Open Source Web Development Site</title>
    <link>http://www.devshed.com</link>
    <description>mos_rss</description>
    <language>en-us</language>
    <lastBuildDate>Tue, 27 Apr 2004 12:39:24 -0400</lastBuildDate>

      <item>
          <title>The Power of CSS</title>
          <link>
            http://www.devshed.com/c/a/Style-Sheets/The-Power-of-CSS/
          </link>
          <description>
            CSS or cascading style sheets are used to create a set of styles that can be applied to your fonts, ...
          </description>
      </item>
... and many more item tags...

IF you note carefully… The most important tag is the [item] tag, where there are sub tags [title], [link], [description], and these sub tags are at the level 4 The tags [title], [link], [description], [language], [lastBuildDate] which provide the general info of the website are at level 3

Now we just have to use the $vals array and get out the information, we do it using a simple for loop

for ($i=0; $i<count($vals); $i++)
{
	//get the primary info
	if ($vals[$i]['tag']=="TITLE" && $vals[$i]['level']==3) {
		$title = $vals[$i]['value'];
	}
	if ($vals[$i]['tag']=="LINK" && $vals[$i]['level']==3) {
		$link = $vals[$i]['value'];
	}
	if ($vals[$i]['tag']=="DESCRIPTION" && $vals[$i]['level']==3) {
		$desc = $vals[$i]['value'];
	}
	if ($vals[$i]['tag']=="LASTBUILDDATE" && $vals[$i]['level']==3) {
		$dt = strtotime($vals[$i]['value']);
	}

	//get the main feed
	if ($vals[$i]['tag']=="TITLE" && $vals[$i]['level']==4) {
		$arr['title'][] = $vals[$i]['value'];
	}
	if ($vals[$i]['tag']=="LINK" && $vals[$i]['level']==4) {
		$arr['link'][] = $vals[$i]['value'];
	}
	if ($vals[$i]['tag']=="DESCRIPTION" && $vals[$i]['level']==4) {
		$arr['desc'][] = $vals[$i]['value'];
	}
}

OK, Now we have all the required information only !

2 thoughts on “Reading XML RSS Feed”

  1. With havin so much content and articles do you ever run
    into any issues of plagorism or copyright violation? My website has a lot of completely unique content
    I’ve either written myself or outsourced but it looks like a lot of it is popping it up all over the web without my authorization. Do you know any methods to help reduce content from being ripped off? I’d definitely appreciate it.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Reading XML RSS Feed

These days there are many websites from which you you can publish their latest information on YOUR site, How ? The XML way.

Sites like Devshed.com, Devarticles.com, XML.com provide an XML format which you can use. But since the format is XML, it can’t be just shown directly, there has to be some sort of formatting done to it. XML-Stylesheet is one way and the other one, that I’ll be explaining to you is using PHP.

xmlCommonly you can see an image like this for feed This is the link from where you can get the XML Feed, or syndicate its content

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.