On Fri, Jun 14, 2002 at 11:35:04PM +1000, Necro wrote: > 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>
Man, that's REALLY bad XML. > 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. I'd stop when it hits the ending </item> tag. Take a look at http://www.analysisandsolutions.com/code/phpxml.htm. For your case, in the EndHandler() function, put in the case 'ITEM' In that case, have the code process the data you've accumulated and exit. But, if you want to stick with your methodology, below, here's a possibility: 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 )) { $Line = fgets( $FILE, 1024 ); fwrite( $RDF, $Line); if ( preg_match('/<\/item>/', $Line) ) { break; } } fclose( $RDF ); fclose( $FILE ); } -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php