Connecting Tech Pros Worldwide Help | Site Map

Q: How do I parse values from a RSS feed?

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 08:41 AM
Charles Stricklin
Guest
 
Posts: n/a
Default Q: How do I parse values from a RSS feed?

If I have an RSS newsfeed like this:

<?xml version="1.0" encoding="utf-8"?><!-- generator="whocares" -->
<rss version="0.92">
<channel>
<title>Website Name</title>
<link>http://www.websiteurl.com</link>
<description>Description of website</description>
<lastbuilddate>Sun, 19 Sep 2004 04:34:52 +0000</lastbuilddate>
<docs>http://backend.userland.com/rss092</docs>

<item>
<title>1st Title</title>
<description>1st Description</description>
<link>http://www.websiteurl.com/1stlink/</link>
</item>

<item>
<title>2nd Title</title>
<description>2nd Description</description>
<link>http://www.websiteurl.com/2ndlink/</link>
</item>
</channel>
</rss>

And the following code is used to parse that file/feed:

<?php
$feed = 'http://www.example.com/feed/rss/';

/* ...create and XML parser... */
$xml_parser = xml_parser_create();

/* ...open the feed and parse it... */
$fp = @fopen($feed, 'rb');
if (is_resource($fp)) {
xml_parse_into_struct( $xml_parser, $fp, $vals, $index );
}
@fclose($fp);

/* ...free parser */
xml_parser_free( $xml_parser );
?>

How do I extract the values from $xml_parser?




  #2  
Old July 17th, 2005, 08:45 AM
Marcin Dobrucki
Guest
 
Posts: n/a
Default Re: Q: How do I parse values from a RSS feed?


How about: http://pear.php.net/package/XML_RSS


Charles Stricklin wrote:[color=blue]
> If I have an RSS newsfeed like this:
>
> <?xml version="1.0" encoding="utf-8"?><!-- generator="whocares" -->
> <rss version="0.92">
> <channel>
> <title>Website Name</title>
> <link>http://www.websiteurl.com</link>
> <description>Description of website</description>
> <lastbuilddate>Sun, 19 Sep 2004 04:34:52 +0000</lastbuilddate>
> <docs>http://backend.userland.com/rss092</docs>
>
> <item>
> <title>1st Title</title>
> <description>1st Description</description>
> <link>http://www.websiteurl.com/1stlink/</link>
> </item>
>
> <item>
> <title>2nd Title</title>
> <description>2nd Description</description>
> <link>http://www.websiteurl.com/2ndlink/</link>
> </item>
> </channel>
> </rss>
>
> And the following code is used to parse that file/feed:
>
> <?php
> $feed = 'http://www.example.com/feed/rss/';
>
> /* ...create and XML parser... */
> $xml_parser = xml_parser_create();
>
> /* ...open the feed and parse it... */
> $fp = @fopen($feed, 'rb');
> if (is_resource($fp)) {
> xml_parse_into_struct( $xml_parser, $fp, $vals, $index );
> }
> @fclose($fp);
>
> /* ...free parser */
> xml_parser_free( $xml_parser );
> ?>
>
> How do I extract the values from $xml_parser?
>
>
>[/color]
  #3  
Old July 17th, 2005, 08:46 AM
Andy Hassall
Guest
 
Posts: n/a
Default Re: Q: How do I parse values from a RSS feed?

On Sun, 19 Sep 2004 22:33:40 -0500, "Charles Stricklin"
<charlesstricklin@bellsouth.net> wrote:
[color=blue]
>If I have an RSS newsfeed like this:
>
>How do I extract the values [...][/color]

Not answering directly, but look up MagpieRSS, it's simpler and has some nice
RSS-specific features.

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.