php get rss tag using DOM

View: New views
8 Messages — Rating Filter:   Alert me  

php get rss tag using DOM

by Morris-25 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I am trying to write a programme to read a rss xml file.

...
<media:content url="*exampe.jpg*" ...>
...

    scan anyone tell me how to get the url attribute? I wrote some codes
similar:


 $doc = new DOMDocument;
 $doc->load($myFlickrRss);

 $r = $doc->getElementsByTagName('media:content');
 for($i=0;$i<=$r->length;$i++)  {

  // help here

 }

Re: php get rss tag using DOM

by Nathan Rixham :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Morris wrote:

> Hi,
>
> I am trying to write a programme to read a rss xml file.
>
> ...
> <media:content url="*exampe.jpg*" ...>
> ...
>
>     scan anyone tell me how to get the url attribute? I wrote some codes
> similar:
>
>
>  $doc = new DOMDocument;
>  $doc->load($myFlickrRss);
>
>  $r = $doc->getElementsByTagName('media:content');
>  for($i=0;$i<=$r->length;$i++)  {
>
>   // help here
>
>  }
>

use http://rssphp.net/ you can view the source online and it's all done
using DOMDocuments :)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: php get rss tag using DOM

by Morris-25 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I know rss_php, but it doesn't fit my solution.

Is anyone able to help me with my question?

thx

2009/2/8 Nathan Rixham <nrixham@...>

>  Morris wrote:
>
>> Hi,
>>
>> I am trying to write a programme to read a rss xml file.
>>
>> ...
>> <media:content url="*exampe.jpg*" ...>
>> ...
>>
>>    scan anyone tell me how to get the url attribute? I wrote some codes
>> similar:
>>
>>
>>  $doc = new DOMDocument;
>>  $doc->load($myFlickrRss);
>>
>>  $r = $doc->getElementsByTagName('media:content');
>>  for($i=0;$i<=$r->length;$i++)  {
>>
>>  // help here
>>
>>  }
>>
>>
> use http://rssphp.net/ you can view the source online and it's all done
> using DOMDocuments :)
>

Re: php get rss tag using DOM

by Rob Richards-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Morris wrote:

> I know rss_php, but it doesn't fit my solution.
>
> Is anyone able to help me with my question?
>
> thx
>
> 2009/2/8 Nathan Rixham <nrixham@...>
>
>>  Morris wrote:
>>
>>> Hi,
>>>
>>> I am trying to write a programme to read a rss xml file.
>>>
>>> ...
>>> <media:content url="*exampe.jpg*" ...>
>>> ...
>>>
>>>    scan anyone tell me how to get the url attribute? I wrote some codes
>>> similar:
>>>
>>>
>>>  $doc = new DOMDocument;
>>>  $doc->load($myFlickrRss);
>>>
>>>  $r = $doc->getElementsByTagName('media:content');
>>>  for($i=0;$i<=$r->length;$i++)  {
>>>
>>>  // help here
>>>
>>>  }
>>>
>>>
>> use http://rssphp.net/ you can view the source online and it's all done
>> using DOMDocuments :)
>>
>

First off, you should be using getElementsByTagNameNS since you are
working with a namespaced document. I am assuming its a Yahoo Media RSS
feed, so you would get the elements via:
$r = $doc->getElementsByTagNameNS("http://search.yahoo.com/mrss/",
"content");

Then to output the url attribute value:

foreach ($r AS $elem) {
    echo $elem->getAttribute("url") . "\n";
}

Rob

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: php get rss tag using DOM

by Rodgerr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Morris-25 wrote:
Hi,

I am trying to write a programme to read a rss xml file.

...
<media:content url="*exampe.jpg*" ...>
...

    scan anyone tell me how to get the url attribute? I wrote some codes
similar:


 $doc = new DOMDocument;
 $doc->load($myFlickrRss);

 $r = $doc->getElementsByTagName('media:content');
 for($i=0;$i<=$r->length;$i++)  {

  // help here

 }
Hi. Our site http://rssphp.blogspot.net is working on providing possible solutions to the problem with different parsing methods in PHP. It's worth to have a look at the options.

--
List Website

Re: php get rss tag using DOM

by Michael A. Peters :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Rodgerr wrote:

>
>
> Morris-25 wrote:
>> Hi,
>>
>> I am trying to write a programme to read a rss xml file.
>>
>> ...
>> <media:content url="*exampe.jpg*" ...>
>> ...
>>
>>     scan anyone tell me how to get the url attribute? I wrote some codes
>> similar:
>>
>>
>>  $doc = new DOMDocument;
>>  $doc->load($myFlickrRss);
>>
>>  $r = $doc->getElementsByTagName('media:content');
>>  for($i=0;$i<=$r->length;$i++)  {
>>

$node = $r->item($i);
if ($node->hasAttribute('url') {
  $url[] = $node->>getAttribute('url');
  }

>>
>>  }

That should give you an array called $url of all the url attributes in
the nodes.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: php get rss tag using DOM

by Michael A. Peters :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Michael A. Peters wrote:

> Rodgerr wrote:
>>
>>
>> Morris-25 wrote:
>>> Hi,
>>>
>>> I am trying to write a programme to read a rss xml file.
>>>
>>> ...
>>> <media:content url="*exampe.jpg*" ...>
>>> ...
>>>
>>>     scan anyone tell me how to get the url attribute? I wrote some codes
>>> similar:
>>>
>>>
>>>  $doc = new DOMDocument;
>>>  $doc->load($myFlickrRss);
>>>
>>>  $r = $doc->getElementsByTagName('media:content');
>>>  for($i=0;$i<=$r->length;$i++)  {
>>>
>
> $node = $r->item($i);
> if ($node->hasAttribute('url') {
>  $url[] = $node->>getAttribute('url');
>  }
>
>>>
>>>  }
>
> That should give you an array called $url of all the url attributes in
> the nodes.
>

$url[] = $node->>getAttribute('url');
should be
$url[] = $node->getAttribute('url');

and don't forget to validate it before spitting it back out on a page
somewhere ...

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: php get rss tag using DOM

by Rodgerr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Getting RSS Feeds is going really good right now, what amazing technology :)
 Nickname Msn
Morris-25 wrote:
Hi,

I am trying to write a programme to read a rss xml file.

...
<media:content url="*exampe.jpg*" ...>
...

    scan anyone tell me how to get the url attribute? I wrote some codes
similar:


 $doc = new DOMDocument;
 $doc->load($myFlickrRss);

 $r = $doc->getElementsByTagName('media:content');
 for($i=0;$i<=$r->length;$i++)  {

  // help here

 }