Step 37 – The readIMSManifest Function

Time to start writing the readIMSManifestFile() function. Let’s create the basic structure.

function readIMSManifestFile($manifestfile) {

  // PREPARATIONS

  // READ THE RESOURCES LIST

  // READ THE ITEMS LIST

  // PROCESS THE ITEMS LIST TO FIND SCOS
  
  // RETURN RESULTS

}

The first section is pretty straightforward since I can build on the code that I created previously.

  // PREPARATIONS

  // load the imsmanifest.xml file
  $xmlfile = new DomDocument;
  $xmlfile->preserveWhiteSpace = FALSE;
  $xmlfile->load($manifestfile);

  // adlcp namespace
  $manifest = $xmlfile->getElementsByTagName('manifest');
  $adlcp = $manifest->item(0)->getAttribute('xmlns:adlcp');

I start by loading the manifest file into a variable, and I read the XML namespace definitions that I need.

Now I move on to reading the resources list. Here’s my initial code.

  // READ THE RESOURCES LIST

  // array to store the results
  $resourceData = array();

  // get the list of resource element
  $resourceList = $xmlfile->getElementsByTagName('resource');

  $r = 0;
  foreach ($resourceList as $rtemp) {

    // decode the resource attributes
    $identifier = $resourceList->item($r)->getAttribute('identifier');
    $resourceData[$identifier]['type'] = $resourceList->item($r)->getAttribute('type');
    $resourceData[$identifier]['scormtype'] = $resourceList->item($r)->getAttribute('adlcp:scormtype');
    $resourceData[$identifier]['href'] = $resourceList->item($r)->getAttribute('href');

    // list of files
    $fileList = $resourceList->item($r)->getElementsByTagName('file');

    $f = 0;
    foreach ($fileList as $ftemp) {
      $resourceData[$identifier]['files'][$f] =  $fileList->item($f)->getAttribute('href');
      $f++;
    }

    $r++;

  }

Pretty much as I did before, but this time I’m storing the data that I read in the $resourceData array. Let’s look at the XML file that I’m reading to see if I’m capturing all of the data. Here’s a typical <resource> element.


   
   
   
   
   
   
   

Whoops … whereas the IMS manifest file that I was reading previously had a single resource which contained multiple files, this manifest file consists of multiple <resource> elements which appear to be linked together by <dependency> elements. So I’m going to have to take a step backward and look at the SCORM 1.2 CAM specification again in far more detail.

This entry was posted in Content Aggregation Model. Bookmark the permalink.