/**
  * Short description of method buildResponseDeclaration
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  DOMElement data
  * @return oat\taoQtiItem\model\qti\ResponseDeclaration
  * @see http://www.imsglobal.org/question/qti_v2p0/imsqti_infov2p0.html#element10074
  */
 protected function buildResponseDeclaration(DOMElement $data)
 {
     $myResponse = new ResponseDeclaration($this->extractAttributes($data), $this->item);
     $data = simplexml_import_dom($data);
     //set the correct responses
     $correctResponseNodes = $data->xpath("*[name(.) = 'correctResponse']");
     $responses = array();
     foreach ($correctResponseNodes as $correctResponseNode) {
         foreach ($correctResponseNode->value as $value) {
             $correct = (string) $value;
             $responses[] = htmlentities($correct);
         }
         break;
     }
     $myResponse->setCorrectResponses($responses);
     //set the mapping if defined
     $mappingNodes = $data->xpath("*[name(.) = 'mapping']");
     foreach ($mappingNodes as $mappingNode) {
         if (isset($mappingNode['defaultValue'])) {
             $myResponse->setMappingDefaultValue(floatval((string) $mappingNode['defaultValue']));
         }
         $mappingOptions = array();
         foreach ($mappingNode->attributes() as $key => $value) {
             if ($key != 'defaultValue') {
                 $mappingOptions[$key] = (string) $value;
             }
         }
         $myResponse->setAttribute('mapping', $mappingOptions);
         $mapping = array();
         foreach ($mappingNode->mapEntry as $mapEntry) {
             $mapping[(string) $mapEntry['mapKey']] = (string) $mapEntry['mappedValue'];
         }
         $myResponse->setMapping($mapping);
         break;
     }
     //set the areaMapping if defined
     $mappingNodes = $data->xpath("*[name(.) = 'areaMapping']");
     foreach ($mappingNodes as $mappingNode) {
         if (isset($mappingNode['defaultValue'])) {
             $myResponse->setMappingDefaultValue(floatval((string) $mappingNode['defaultValue']));
         }
         $mappingOptions = array();
         foreach ($mappingNode->attributes() as $key => $value) {
             if ($key != 'defaultValue') {
                 $mappingOptions[$key] = (string) $value;
             }
         }
         $myResponse->setAttribute('areaMapping', $mappingOptions);
         $mapping = array();
         foreach ($mappingNode->areaMapEntry as $mapEntry) {
             $mappingAttributes = array();
             foreach ($mapEntry->attributes() as $key => $value) {
                 $mappingAttributes[(string) $key] = (string) $value;
             }
             $mapping[] = $mappingAttributes;
         }
         $myResponse->setMapping($mapping, 'area');
         break;
     }
     return $myResponse;
 }