Get information from RSS Feed (Atom)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
BDB100
Forum Newbie
Posts: 8
Joined: Tue Sep 07, 2010 2:15 am

Get information from RSS Feed (Atom)

Post by BDB100 »

Hi,

I have an xml from an RSS-feed like the following example (random data) :

[text]
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<feed xml:base="http://test_url/test/Feed/test.svc/"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/0 ... s/metadata" xmlns="http://www.w3.org/2005/Atom">
<title type="text">Title1</title>
<entry>
<id>http://Product1.com</id>
<title type="text">Product1</title>
<contributor>
<uri>http://www.product1/product1.pdf</uri>
</contributor>
<content type="application/xml">
<m:properties>
<d:ProductName>Product1</d:ProductName>
<d:DescriptionNL>Productbeschrijving1</d:DescriptionNL>
</m:properties>
</content>
</entry>
<entry>
<id>http://Product2.com</id>
<title type="text">Product2</title>
<contributor>
<uri>http://www.product2/product2.pdf</uri>
</contributor>
<content type="application/xml">
<m:properties>
<d:ProductName>Product2</d:ProductName>
<d:DescriptionNL>Productbeschrijving2</d:DescriptionNL>
</m:properties>
</content>
</entry>
</feed>
[/text]

I already have following PHP-code :

Code: Select all

<?php

$url = "http:\\feed_url";

$str = file_get_contents($url);

$xml = simplexml_load_string($str);

echo $xml->title;

foreach ($xml->entry as $item) {
  echo "<h2> <a href=" . $item->contributor->uri . ">" . $item->title . "</a> </h2>";
}

?> 
This code works fine, but I would like to add the ProductName and the DescriptionNL.
However, I am not able to get these data out of the XML-data.

Can anyone help with this problem ?

Grtz,
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Get information from RSS Feed (Atom)

Post by Darhazer »

Code: Select all

$m = $item->content->children('http://schemas.microsoft.com/ado/2007/08/dataservices/metadata')->children('http://schemas.microsoft.com/ado/2007/08/dataservices');
  echo $m->ProductName;
BDB100
Forum Newbie
Posts: 8
Joined: Tue Sep 07, 2010 2:15 am

Re: Get information from RSS Feed (Atom)

Post by BDB100 »

Works perfect !

Thanks a lot.
Post Reply