/** * Unmarshall a DOMElement object corresponding to an XHTML img element. * * @param \DOMElement $element A DOMElement object. * @return \qtism\data\QtiComponent n Img object. * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException */ protected function unmarshall(DOMElement $element) { if (($src = self::getDOMElementAttributeAs($element, 'src')) !== null) { if (($alt = self::getDOMElementAttributeAs($element, 'alt')) === null) { // The XSD does not force the 'alt' attribute to be non-empty, // thus we consider the 'alt' attribute value as an empty string (''). $alt = ''; } $component = new Img($src, $alt); if (($longdesc = self::getDOMElementAttributeAs($element, 'longdesc')) !== null) { $component->setLongdesc($longdesc); } if (($height = self::getDOMElementAttributeAs($element, 'height', 'string')) !== null) { if (stripos($height, '%') === false) { $component->setHeight(intval($height)); } else { $component->setHeight($height); } } if (($width = self::getDOMElementAttributeAs($element, 'width', 'string')) !== null) { if (stripos($width, '%') === false) { $component->setWidth(intval($width)); } else { $component->setWidth($width); } } if (($xmlBase = self::getXmlBase($element)) !== false) { $component->setXmlBase($xmlBase); } $this->fillBodyElement($component, $element); return $component; } else { $msg = "The 'mandatory' attribute 'src' is missing from element 'img'."; throw new UnmarshallingException($msg, $element); } }