Re: Re: XML parser for PHP5
| From: | Matthew Sims | Date: | Wed, 15 Sep 2004 22:20:28 +0000 |
| Subject: | Re: Re: XML parser for PHP5 | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-196795@lists.php.net to get a copy of this message | ||
> Matthew Sims wrote:
>
>> My fault, I should have been more specific. An RSS reader. :) I was
>> using
>> xmlParser-0.3 and feedParser-0.5 to display news sites. Since I've
>> converted to PHP5, they no longer work for me.
>
> definitely a combination of simplexml and DOM would work. You need DOM
> in order to determine what the name of the root node's namespace is to
> find RSS 1.0.
>
> http://php.net/simplexml
> http://php.net/DOM
>
> for example:
>
> <?php
> $rss = simplexml_load_file('http://www.example.com/blah.rss'B›�‘[ª
> Á.Qv,);
> $dom = new domdocument("1.0");
> $dom_rss = $dom->importnode($rss, true);
> $dom_rss = $dom->appendchild($rss);
> if ($dom_rss->namespaceURI == '') {
> $rssversion = '1.0';
> } else {
> $rssversion = $rss['version'];
> }
> switch ($rssversion) {
> case '1.0' :
> case '2.0' :
> if (isset($rss->channel->pubDate)) {
> echo "Publication Date: " . $rss->channel->pubDate . "<br
> />";
> }
>
> case '0.91' :
> case '0.92' :
> case '0.93' :
> case '0.94' :
> echo '<a href="';
> echo $rss->channel->link;
> echo '">' . $rss->channel->title . '</a><br
> />';
> foreach ($rss->channel->item as $item) {
> echo $item->title . '<br />';
> echo '<a href="';
> echo $item->link;
> echo '">' . $item->description . '</a><br
> />';
> }
> break;
> }
> ?>
>
> Of course, the full range RSS tags are available to you as object
> properties, and attributes as array access (like $rss['version'])
>
> Greg
>
Very nice, thank you. This should get my feet wet with a little XML.
--
--Matthew Sims
--<http://killermookie.org>