Jump to content

SimpleXMLElement Issue


Solarpitch

Recommended Posts

Hey Guys,

 

I have a snippet of XML here..

 

<courses>
  <course>
    <id>70</id>
    <name>Marketing and Social Media</name>
    <dates>
      <date>
        <instance_id>6747</instance_id>
        <location />
        <course_type>Day</course_type>
        <date_available>2011/07/13</date_available>
        <time_start>9:30</time_start>
        <time_end>17:00</time_end>
        <availibility>7</availibility>
        <running_dates>
          <running_date>2011/07/13</running_date>
          <running_date>2011/07/14</running_date>
        </running_dates>
      </date>
    </dates>
  </course>

 

I'm trying to run xpath query to return all the courses and running dates associated with it but I dont understand how I get the running_dates?

 

This is what I have..

 


<?php

$xmlstr = "../wp-content/themes/iact/courses.xml";
$xml = new SimpleXMLElement($xmlstr, NULL, TRUE);


foreach ($xml->xpath('//date/running_dates') as $date) {

    $t = "<p class='heading'>". $date->course_type."</p>
          <div class='content'>".$date->running_date."</div>"; // do I need to go into another foreach here to loop all of the running dates? hardly?
    echo $t;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/237984-simplexmlelement-issue/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.