Page 1 of 1

any suggestions on xml feed?

Posted: Mon Sep 12, 2005 4:40 am
by saumya
i am a beginner of php and just now i started walking on php.Now i think i should make an xml reader.CAn i make that if yes how.I mean i want to get the rss feed from one site and read that and put that in my local pc.When i open my local site, it should read that xml feed and show it to me. how to go about it?
thanks for the guidance.

Posted: Mon Sep 12, 2005 5:51 am
by patrikG
Have a look at this thread: viewtopic.php?t=36972

Posted: Mon Sep 12, 2005 6:17 am
by saumya
thanks a lot.
I will go through the link and let you know about the doubts.
thanks

Posted: Mon Sep 12, 2005 6:32 am
by saumya
i tried that class but my browser does not say anything.
myReader.php

Code: Select all

<?php
include_once("studyParser.php");
$xml= new parser("http://www.mozilla.org/reorganization/feed.xml","XMLbasetag","XMLelement"); 
?>
any idea why? I am behind a firewall and got user id and password to access remote sites.I am guessing that is the problem, but can not figureout how to go about it.
thanks

Posted: Mon Sep 12, 2005 6:37 am
by patrikG
saumya wrote:i tried that class but my browser does not say anything.
myReader.php

Code: Select all

<?php
include_once("studyParser.php");
$xml= new parser("http://www.mozilla.org/reorganization/feed.xml","XMLbasetag","XMLelement"); 
?>
any idea why? I am behind a firewall and got user id and password to access remote sites.I am guessing that is the problem, but can not figureout how to go about it.
thanks
You need to replace "XMLbasetag" and "XMLelement" with the xml basetag and the XML base element.

For RSS try

Code: Select all

$rssFeed =new parser("http://www.mozilla.org/reorganization/feed.xml","ITEM","RSS");
to see the output use

Code: Select all

echo'<H3>_$rssFeed->result</H3><XMP>';print_r($rssFeed->result);echo'</XMP>';
Btw. parsing an RSS feed with PHP is not quite "walking", it's more "jogging": a semi-advanced topic. The script I posted on that thread is document according to phpDocumentor - see if you can understand what it's actually doing - which, if you want to learn about PHP, is what you should do anyway.

Posted: Mon Sep 12, 2005 6:49 am
by saumya
no luck here too.
Can u give me the code which exactly out puts the mozilaa rss feed i gave preveously.So that if it works, i can go on and study what exactly should be done to read such type of files?
asking too much but can not help,My browser does not show up anyything now.

Posted: Mon Sep 12, 2005 6:56 am
by patrikG
using the code I've posted above

Code: Select all

include_once("class_xml_parser.inc.php");
$rssFeed =new parser("http://www.mozilla.org/reorganization/feed.xml","ITEM","RSS");
echo'<H3>_$rssFeed->result</H3><XMP>';print_r($rssFeed->result);echo'</XMP>';
yields:
XML parsing result wrote: <H3>_$rssFeed->result</H3><XMP>Array
(
[-1] => Array
(
[TITLE] => Mozilla Foundation Reorganization
[LINK] => http://www.mozilla.org/reorganization/
[DESCRIPTION] => Blog links and posts related to the Mozilla Foundation's recent reorganization announcement.
)

[0] => Array
(
[TITLE] => Interview with Mitchell Baker at OSCON 2005 (Audio)
[DESCRIPTION] => MP3 podcast of interview with Mitchell Baker, President, Mozilla Corporation recorded at OSCON 2005.
[PUBDATE] => Thu, 04 Aug 2005 12:49:00 -0800
[LINK] => http://ftp.mozilla.org/pub/mozilla.org/ ... n-2005.mp3
)

[1] => Array
(
[TITLE] => Chris Blizzard - Mozilla Corporation
[DESCRIPTION] => Chris Blizzard, Board Member, Mozilla Corporation
[LINK] => http://www.0xdeadbeef.com/html/2005/08/#200508032005
[PUBDATE] => Wed, 03 Aug 2005 16:27:00 -0800
)

[2] => Array
(
[TITLE] => Tristan Nitot - Mozilla Foundation Reorganization
[DESCRIPTION] => Tristan Nitot, President, Mozilla Europe
[LINK] => http://standblog.org/blog/2005/08/03/93 ... ganization
[PUBDATE] => Wed, 02 Aug 2005 23:59:00 -0800
)

[3] => Array
(
[TITLE] => Karim Lakhani - Organizational Innovation: The Mozilla Corporation
[DESCRIPTION] => Karim Lakhani, Open Source Researcher, MIT
[LINK] => http://spoudaiospaizen.net/archives/200 ... rporation/
[PUBDATE] => Wed, 02 Aug 2005 23:59:00 -0800
)

[4] => Array
(
[TITLE] => Frank Hecker - The Mozilla Foundation Reorganization
[DESCRIPTION] => Frank Hecker, Director of Policy, Mozilla Foundation
[LINK] => http://www.hecker.org/mozilla/dot-reorg/
[PUBDATE] => Tue, 02 Aug 2005 23:59:00 -0800
)

[5] => Array
(
[TITLE] => Mitchell Baker - Organizing the Mozilla Project: Mozilla Corporation
[DESCRIPTION] => Mitchell Baker, President, Mozilla Corporation and Board Member, Mozilla Foundation
[LINK] => http://weblogs.mozillazine.org/mitchell ... the_1.html
[PUBDATE] => Tue, 02 Aug 2005 23:59:00 -0800
)

)
</XMP>

Posted: Mon Sep 12, 2005 7:04 am
by saumya
why my page does not show anything? i am doing something nonsense or missing out something :( :(

Code: Select all

<?php
include_once("class_xml_parser.inc.php");
$rssFeed =new parser("http://www.mozilla.org/reorganization/feed.xml","ITEM","RSS");
echo'<H3>_$rssFeed->result</H3><XMP>';print_r($rssFeed->result);echo'</XMP>'; 
?>
this does not show up anything.

Posted: Mon Sep 12, 2005 7:16 am
by patrikG
add

Code: Select all

error_reporting (E_ALL);
at the top of the file from where you include the class, run it and post the result.

Posted: Mon Sep 12, 2005 7:35 am
by saumya
now my file lloks like this

Code: Select all

<?php
error_reporting (E_ALL); 
include_once("class_xml_parser.inc.php");
$rssFeed =new parser("http://www.mozilla.org/reorganization/feed.xml","ITEM","RSS");
echo'<H3>_$rssFeed->result</H3><XMP>';print_r($rssFeed->result);echo'</XMP>'; 
?>
but still browser is empty

Posted: Mon Sep 12, 2005 7:38 am
by patrikG
you don't seem to be getting the rss-feed. Try

Code: Select all

$fp = fopen($file, "r");
while($data=fread($fp,4096)){
        $xml[]=$data;
}
echo'<H3>_$xml</H3><XMP>';print_r($xml);echo'</XMP>';
This checks whether the script is receiving the feed.

Posted: Mon Sep 12, 2005 7:55 am
by timvw
I've found http://magpierss.sf.net very useful :)

But you might want to solve your fetching remote data first... Meaby you ('re webhost) has been blocked by mozilla website because you fetch the file too many times in a given timeslot..

Posted: Mon Sep 12, 2005 7:57 am
by patrikG
oops, replace $file with "http://www.mozilla.org/reorganization/feed.xml" in the first line of the script I posted above:

Code: Select all

$fp = fopen("http://www.mozilla.org/reorganization/feed.xml", "r");
I am behind a firewall and got user id and password to access remote sites.
That might be the problem. Ask your IT-deparment how to run scripts fetching remote data.

Posted: Mon Sep 12, 2005 11:19 pm
by saumya

Code: Select all

<?php
//checking for feed
$file="http://www.mozilla.org/reorganization/feed.xml";
$fp = fopen($file, "r");
while($data=fread($fp,4096)){
        $xml[]=$data;
}
echo'<H3>_$xml</H3><XMP>';
print_r($xml);
echo'</XMP>';
?>
Now my code is that, but without result.I think the problem is with the getting the data from net.
But then how the rss readers such as thunderbird gets data?!!
thanks a lot