XML Feed
| From: | Necro | Date: | Fri, 14 Jun 2002 13:35:04 +0000 |
| Subject: | XML Feed | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-102208@lists.php.net to get a copy of this message | ||
I am currently trying to implement XML Parsing on a site using the XML News
Feed of another site. The site puts two versions of the news in its file
though:
- <item>
<title>Tsunami 2265 Date, Demo</title>
<link>http://www.shacknews.com/onearticle.x/20959</link>
</item>
- <ITEM>
<SUBJECT>Tsunami 2265 Date, Demo</SUBJECT>
<URL>http://www.shacknews.com/onearticle.x/20959</URL>
<CATEGORY>General</CATEGORY>
</ITEM>
I have a script that is meant to parse the file which is downloaded to a
local file hourly. The trouble is that the script tries parsing both lots
and I only wish it to parse the top half and to stop when it reaches the
entries using <SUBJECT> tags.
Does anyone have a solution for this? The script below is what I use to echo
the news onto my site. The script attached is the script that is meant to
parse the xml document.
<? include( "includes/xmlfeed.php" );
$rdffile = "shacknews.xml";
$remote = "http://www.shacknews.com/shackfeed.xml";
$refreshtime = time() - 3600;
?>
<?
if ((filemtime($rdffile) < $refreshtime) || (filesize($rdffile) == 0)) {
$RDF = fopen( $rdffile, "w" ) or die( "Cannot open $rdffile" );
$FILE = fopen( $remote, "r" ) or die( "Cannot open $remote" );
while (!feof( $FILE )) {
fwrite( $RDF, fgets( $FILE, 1024 ));
}
fclose( $RDF );
fclose( $FILE );
}
parseRDF( $rdffile );
?>
-----
Andrew.