XML parse problem

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


$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.

<title>Latest Jobs from Wemploy Specialist Recruitment</title>
<description>Get the latest 15 job vacancies to your desktop</description>
<jobname>HNW Manager</jobname>
<jobsector>Financial Services </jobsector>
...... text here ......
<jobdate>2/1/2010 5:35:57 PM</jobdate>
<!-- more jobdetails nodes -->

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.