Step 34 – Reading the IMS Manifest File – Resources

I’m going to start simple by reading the resource information from the manifest file. To do this, I’m going to use the DOM extension to PHP that’s part of the core of PHP5. This will allows me to parse and read the manifest XML data. You can find the documentation for the DOM extension [here].

Here’s my code.

<?php 

/*

VS SCORM - CAMreader.php 
Rev 1.0 - Friday, October 02, 2009
Copyright (C) 2009, Addison Robson LLC

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, 
Boston, MA 02110-1301, USA.

*/

// ------------------------------------------------------------------------------------
// Preparations
// ------------------------------------------------------------------------------------

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

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

// ------------------------------------------------------------------------------------
// Read the Resources (Assets) List
// ------------------------------------------------------------------------------------

// output table header row
$resListTable  = "<table cellpadding=3 cellspacing=0 border=1>\n";
$resListTable .= "<tr>\n";
$resListTable .= "\t<td valign=top align=left><b>Identifier</b></td>\n";
$resListTable .= "\t<td valign=top align=left><b>Type</b></td>\n";
$resListTable .= "\t<td valign=top align=left><b>SCORMType</b></td>\n";
$resListTable .= "\t<td valign=top align=left><b>HREF</b></td>\n";
$resListTable .= "\t<td valign=top align=left><b>Files</b></td>\n";
$resListTable .= "</tr>\n";

// get the resources element
$resourcesList = $dom->getElementsByTagName('resources');

// iterate over each of the resources
foreach ($resourcesList as $resourcesListRow) {

  $resourceList = $resourcesListRow->getElementsByTagName('resource');

  foreach ($resourceList as $resourceListRow) {

    // decode the attributes
    // e.g. <resource identifier="A001" type="webcontent" adlcp:scormtype="sco" href="a001index.html">
    $identifier = $resourceListRow->getAttribute('identifier');
    $type = $resourceListRow->getAttribute('type');
    $scormtype = $resourceListRow->getAttribute('adlcp:scormtype');
    $href = $resourceListRow->getAttribute('href');

    // make safe for display
    $identifier = cleanVar($identifier);
    $type = cleanVar($type);
    $scormtype = cleanVar($scormtype);
    $href = cleanVar($href);

    // list of files
    $files = array();
    $fileList = $resourceListRow->getElementsByTagName('file');
    foreach ($fileList as $fileListRow) {
      $files[] = cleanVar($fileListRow->getAttribute('href'));
    }
    $filesText = implode('<br>',$files);

    // table row
    $resListTable .= "<tr>\n";
    $resListTable .= "\t<td valign=top align=left>$identifier</td>\n";
    $resListTable .= "\t<td valign=top align=left>$type</td>\n";
    $resListTable .= "\t<td valign=top align=left>$scormtype</td>\n";
    $resListTable .= "\t<td valign=top align=left>$href</td>\n";
    $resListTable .= "\t<td valign=top align=left>$filesText</td>\n";
    $resListTable .= "</tr>\n";

    // resource array
    $resource[$identifier]['type'] = $type;
    $resource[$identifier]['scormtype'] = $scormtype;
    $resource[$identifier]['href'] = $href;

  }

}

$resListTable .= "</table>\n";

// ------------------------------------------------------------------------------------
// Functions
// ------------------------------------------------------------------------------------
function cleanVar($value) {
  $value = (trim($value) == "") ? " " : htmlentities(trim($value));
  return $value;
}

?>
<html>
<head>
  <title></title>
  <style type="text/css">
  p,td,li,body,input,select,textarea {
    font-family: verdana, sans-serif;
    font-size: 10pt;
  }
  h1 {
    font-weight: bold;
    font-size: 12pt;
  }
  h2 {
    font-weight: bold;
    font-size: 11pt;
  }
  a:link, a:active, a:visited {
    color: blue;
    text-decoration: none;
  }
  a:hover {
    color: blue;
    text-decoration: underline;
  }
  </style>
</head>
<body bgcolor="#ffffff">

<h2>Resources = Assets</h2>
<p><?php print $resListTable; ?>

</body>
</html>

Let’s see how this breaks down (omitting discussion of the more obvious formatting and output code sections).

  • Lines 30-33: I create a new object and load the contents of the ‘imsmanifest.xml’ file into that object.
     
  • Lines 35-37: I read the <manifest> tag and read the value of the ‘xmlns:adlcp’ attribute. I’ll need this later.
     
  • Lines 54: I read the list of <resource> tags into an array.
     
  • Lines 57-60: I’m iterating through my list of resources, reading each one in turn.
     
    • Lines 64-75: For each resource, I’m reading the information that’s stored in the tag attributes.
       
    • Lines 77-83: Then, I’m reading the list of <file> tags for this <resource> tag, and decoding their content.
       
  • Lines 94-97: Store the resource data into an array so that I can reference it later.
     
  • Lines 108-111: Just a convenient routine to format the output for display on the screen.
     

Time to read the manifest file. Here’s the <resources> section of the file:


	
		 
		 
		 
		 
		 
	

Looks fairly simple. I have one resource which consists of 5 files. The “adlcp:scormtype” attribute of the <resource> tag specifies that the resource is a SCO (course), and the “href” attribute of the <resource> tag defines the entry point (start file) as ‘Simulation.htm’.

And here’s the output that I get from my code:

Identifier Type SCORMType HREF Files
P1_RES webcontent sco Simulation.htm Simulation.swf
Simulation.htm
SCORM_support/scorm_support.htm
SCORM_support/scorm_support.js
SCORM_support/scorm_support.swf

So far, so good. Next step, read the <organizations> section of the file.

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

3 Responses to Step 34 – Reading the IMS Manifest File – Resources

  1. panagiotis says:

    Hello, i wonder if you could help me in reading a similar IMS manifest file, and we can work it out!
    Thanks

  2. Steve Addison says:

    What are the problems that you’re having?

  3. Kevin Mark says:

    So this is a scorm player? I’m currently working on a similar project. I will try your code. THanks

Leave a Reply

Your email address will not be published. Required fields are marked *