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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.