/**
  * Instantiate and fill a QtiComponentCollection
  *
  * @param ReflectionClass $class
  * @param array $values
  * @return \qtism\data\QtiComponentCollection|null
  */
 private function createComponentCollection(ReflectionClass $class, $values)
 {
     $collection = $class->newInstance();
     if ($collection instanceof ViewCollection) {
         foreach ($values as $value) {
             $collection[] = View::getConstantByName($value);
         }
         return $collection;
     }
     if ($collection instanceof QtiComponentCollection) {
         foreach ($values as $value) {
             $collection->attach($this->arrayToComponent($value, null, false));
         }
         return $collection;
     }
     if ($collection instanceof IntegerCollection || $collection instanceof StringCollection) {
         foreach ($values as $value) {
             $collection[] = $value;
         }
         return $collection;
     }
     return null;
 }
<?php

use qtism\runtime\rendering\markup\AbstractMarkupRenderingEngine;
use qtism\data\View;
use qtism\data\ViewCollection;
use qtism\data\storage\xml\XmlDocument;
use qtism\runtime\rendering\markup\xhtml\XhtmlRenderingEngine;
require_once dirname(__FILE__) . '/../../qtism/qtism.php';
$doc = new XmlDocument();
$doc->load('../samples/rendering/rubricblock_1.xml');
$renderer = new XhtmlRenderingEngine();
if (isset($argv[1])) {
    if (strpos($argv[1], ',') !== false) {
        $strviews = explode(',', $argv[1]);
        $view = new ViewCollection();
        foreach ($strviews as $v) {
            $view[] = View::getConstantByName(trim($v));
        }
    } else {
        $view = new ViewCollection(array(View::getConstantByName(trim($argv[1]))));
    }
    $renderer->setViewPolicy(AbstractMarkupRenderingEngine::CONTEXT_AWARE);
    $renderer->setViews($view);
}
$rendering = $renderer->render($doc->getDocumentComponent());
$rendering->formatOutput = true;
echo $rendering->saveXML();
 /**
  * Unmarshall a DOMElement object corresponding to a QTI outcomeDeclaration element.
  * 
  * @param DOMElement $element A DOMElement object.
  * @return QtiComponent An OutcomeDeclaration object.
  * @throws UnmarshallingException 
  */
 protected function unmarshall(DOMElement $element)
 {
     try {
         $baseComponent = parent::unmarshall($element);
         $object = new OutcomeDeclaration($baseComponent->getIdentifier());
         $object->setBaseType($baseComponent->getBaseType());
         $object->setCardinality($baseComponent->getCardinality());
         $object->setDefaultValue($baseComponent->getDefaultValue());
         // deal with views.
         if (($views = static::getDOMElementAttributeAs($element, 'view')) != null) {
             $viewCollection = new ViewCollection();
             foreach (explode(" ", $views) as $viewName) {
                 $viewCollection[] = View::getConstantByName($viewName);
             }
             $object->setViews($viewCollection);
         }
         // deal with interpretation.
         if (($interpretation = static::getDOMElementAttributeAs($element, 'interpretation')) != null) {
             $object->setInterpretation($interpretation);
         }
         // deal with longInterpretation.
         if (($longInterpretation = static::getDOMElementAttributeAs($element, 'longInterpretation')) != null) {
             $object->setLongInterpretation($longInterpretation);
         }
         // deal with normalMaximum.
         if (($normalMaximum = static::getDOMElementAttributeAs($element, 'normalMaximum', 'float')) !== null) {
             $object->setNormalMaximum($normalMaximum);
         }
         // deal with normalMinimum.
         if (($normalMinimum = static::getDOMElementAttributeAs($element, 'normalMinimum', 'float')) !== null) {
             $object->setNormalMinimum($normalMinimum);
         }
         // deal with matseryValue.
         if (($masteryValue = static::getDOMElementAttributeAs($element, 'masteryValue', 'float')) !== null) {
             $object->setMasteryValue($masteryValue);
         }
         // deal with lookupTable.
         $interpolationTables = $element->getElementsByTagName('interpolationTable');
         $matchTable = $element->getElementsByTagName('matchTable');
         if ($interpolationTables->length == 1 || $matchTable->length == 1) {
             // we have a lookupTable defined.
             $lookupTable = null;
             if ($interpolationTables->length == 1) {
                 $lookupTable = $interpolationTables->item(0);
             } else {
                 $lookupTable = $matchTable->item(0);
             }
             $lookupTableMarshaller = $this->getMarshallerFactory()->createMarshaller($lookupTable, array($object->getBaseType()));
             $object->setLookupTable($lookupTableMarshaller->unmarshall($lookupTable));
         }
         return $object;
     } catch (InvalidArgumentException $e) {
         $msg = "An unexpected error occured while unmarshalling the outcomeDeclaration.";
         throw new UnmarshallingException($msg, $element, $e);
     }
 }