I have an XML parsing script that’s operating a bit quirky. It parses a daily xml feed containing jobs to be featured on my career board. The most urgent problem I need fixed is that old jobs are not dropping off. If a job in my db is not present in the new feed it needs to be deactivated. Here is my preliminary code I was hoping to get some outside thoughts on. -Thanks
$doc = new DOMDocument(); //create a new domdocument to sort through xml tree
$doc->load( ‘/path/daily_jobs.xml’ ); //load the daily job feed
$jobAds = $doc->getElementsByTagName( “jobAd” ); //create a new instance for every incurrance of a jobAd
foreach( $jobAds as $jobAd ) { //loop through each job in feed
$externalJobAdIds=$jobAd->getElementsByTagName( “externalJobAdId” ); //capture externalJobAdId nodes and set them to a variable to be used as unique identifier
$newJobs = array(); //create array to hold id’s of the new jobs
$externalJobAdIds = $newJobs; //push id’s into array
$query = “SELECT externalJobAdId FROM jobs WHERE company_id = 8060”; //run query to capture job id’s already present in db
$oldJobs = mysql_query($query); //store results
foreach($oldJobs as $job) {//loop through results
if(!in_array($newJobs)) { //check if old jobs are still present in today’s feed
$query = “DELETE * FROM jobs WHERE externalJobAdId = '” . $job . “'”; //delete job if it is not in today’s feed
mysql_query($query);
}
}
}