XML parse problem

I have something very similar which works, but I can’t see why this doesn’t.

<?php

$rss_url = "http://www.wemploy.com/xml/jobs-in-spain.asp";

$xml = simplexml_load_file($rss_url);

foreach($xml->channel->jobdetails as $jobdetails)
{

$job_wemploy_id		=	$jobdetails->jobid;
$job_name			=	$jobdetails->jobname;
$job_sector			=	$jobdetails->jobsector;
$job_desc			=	$jobdetails->jobdesc;
$job_link			=	$jobdetails->joblink;
$job_date			=	$jobdetails->jobdate;

echo "$job_name <br>";

}

echo "</div>";
?>

The main problem, as per your previous threads, is not using the right path to loop over. As rajug says, you should be using $xml->jobdetails. Also see your previous thread on this subject and why that worked for the XML in that thread, but not for the XML in this thread. (:

Yes. You can use directly a node.

The secret to getting simplexml to do what you want is having an intimate knowledge of the XML it will be working with. eg.

<channel>
<title>Latest Jobs from Wemploy Specialist Recruitment</title>
<link>http://www.wemploy.com</link>
<description>Get the latest 15 job vacancies to your desktop</description>
<language>en-us</language>
	<jobdetails>
<jobid>2456</jobid>
<jobname>HNW Manager</jobname>
<jobsector>Financial Services </jobsector>
	<jobdesc><![CDATA[
...... text here ......
]]></jobdesc>
	<joblink>
http://www.wemploy.com/jobs-spain/hnw-manager-2456.html
</joblink>
<jobdate>2/1/2010 5:35:57 PM</jobdate>
</jobdetails>
<!-- more jobdetails nodes -->
<channel>

You need to know both the node names and the tree structure.


$rss_url = "http://www.wemploy.com/xml/jobs-in-spain.asp"; 
$xml = simplexml_load_file($rss_url); 
foreach($xml->jobdetails as $jobdetails){ 
    $job_name = $jobdetails->jobname;
    echo "$job_name <br>"; 
}

is that because I was looping over channel node rather than each job details node?

This is going in to my head, I can feel it.