Unmarshall a DOMElement object corresponding to a printedVariable element.

@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A PrintedVariable object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException
968971
protected function unmarshall(DOMElement $element)
    {
        $version = $this->getVersion();
        
        if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) {
            $component = new PrintedVariable($identifier);

            if (($format = $this->getDOMElementAttributeAs($element, 'format')) !== null) {
                $component->setFormat($format);
            }

            if (Version::compare($version, '2.1.0', '>=') === true && ($powerForm = $this->getDOMElementAttributeAs($element, 'powerForm', 'boolean')) !== null) {
                $component->setPowerForm($powerForm);
            }

            if (($base = $this->getDOMElementAttributeAs($element, 'base')) !== null) {
                $component->setBase((Format::isInteger($base) === true) ? intval($base) : $base);
            }

            if (($index = $this->getDOMElementAttributeAs($element, 'index')) !== null) {
                $component->setIndex((Format::isInteger($index) === true) ? intval($index) : $base);
            }

            if (Version::compare($version, '2.1.0', '>=') === true && ($delimiter = $this->getDOMElementAttributeAs($element, 'delimiter')) !== null) {
                $component->setDelimiter($delimiter);
            }

            if (($field = $this->getDOMElementAttributeAs($element, 'field')) !== null) {
                $component->setField($field);
            }

            if (Version::compare($version, '2.1.0', '>=') === true && ($mappingIndicator = $this->getDOMElementAttributeAs($element, 'mappingIndicator')) !== null) {
                $component->setMappingIndicator($mappingIndicator);
            }

            if (($xmlBase = self::getXmlBase($element)) !== false) {
                $component->setXmlBase($xmlBase);
            }

            $this->fillBodyElement($component, $element);

            return $component;
        } else {
            $msg = "The mandatory 'identifier' attribute is missing from the 'printedVariable' element.";
            throw new UnmarshallingException($msg, $element);
        }
    }
47135
public static function parseElement($element)
    {
        if ($element->getName() == "rowset") {
            $re = new RowSet($element);
        } elseif ($element->getName() == "result" && $element->member) { // corp/MemberSecurity workaround
            $container = new Container();
            $container->addElement('members', new PhealRowSet($element, 'members', 'member'));
            $re = new Element('result', $container);
        } else {
            $key = $element->getName();
            $echilds = $element->children();
            if (count($echilds) > 0) {
                $container = new Container();
                foreach ($echilds as $celement) {
                    $cel = Element::parseElement($celement);
                    if (count($celement->attributes()) > 0) {
                        $container->addElement($cel->_name, $cel);
                    } else {
                        $container->addElement($cel->_name, $cel->_value);
                    }
                }
                $value = $container;
            } else {
                $value = (String)$element;
            }

            $re = new Element($key, $value);
            /** @var $element \SimpleXMLElement */
            if (count($element->attributes()) > 0) {
                foreach ($element->attributes() as $name => $attelem) {
                    $re->addAttrib($name, (String)$attelem);
                }
            }

        }
        return $re;
    }
1324528
private function parseElement(array $element)
    {
        $elementXml = $this->dom->createElement('xsd:element');
        foreach ($element as $key => $value) {
            if (in_array($key, array('sequence', 'all', 'choice'))) {
                if (is_array($value)) {
                    $complexType = $this->dom->createElement('xsd:complexType');
                    if (count($value) > 0) {
                        $container = $this->dom->createElement('xsd:' . $key);
                        foreach ($value as $subElement) {
                            $subElementXml = $this->parseElement($subElement);
                            $container->appendChild($subElementXml);
                        }

                        $complexType->appendChild($container);
                    }

                    $elementXml->appendChild($complexType);
                }
            } else {
                $elementXml->setAttribute($key, $value);
            }
        }

        return $elementXml;
    }
1193862
protected function getElementConfig(DOMElement $element)
	{
		$config = [];
		foreach ($element->attributes as $attribute)
		{
			$config[$attribute->name][] = $attribute->value;
		}
		foreach ($element->childNodes as $childNode)
		{
			if ($childNode instanceof DOMElement)
			{
				$config[$childNode->nodeName][] = $this->getValueFromElement($childNode);
			}
		}

		return $this->flattenConfig($this->convertValueTypes($config));
	}
342915
public function toXML(DOMElement $parent) : DOMElement
    {
        Assert::same($this->getElement()->namespaceURI, Constants::NS_SAML);
        Assert::same($this->getElement()->localName, "AttributeValue");

        return Utils::copyElement($this->element, $parent);
    }
539073
public function unmarshall(DOMElement $element)
    {
        if (($responseIdentifier = $this->getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) {
            
            if (($minConstraint = $this->getDOMElementAttributeAs($element, 'minConstraint', 'integer')) !== null) {
                
                if (($maxConstraint = $this->getDOMElementAttributeAs($element, 'maxConstraint', 'integer')) !== null) {
                    
                    if (($patternMask = $this->getDOMElementAttributeAs($element, 'patternMask')) === null) {
                        $patternMask = '';
                    }
                    try {
                        $component = new ResponseValidityConstraint($responseIdentifier, $minConstraint, $maxConstraint, $patternMask);
                    
                        // Find child associationValidityConstraint elements if any.
                        $associationValidityConstraintElts = $this->getChildElementsByTagName($element, 'associationValidityConstraint');
                            
                        foreach ($associationValidityConstraintElts as $associationValidityConstraintElt) {
                            $marshaller = $this->getMarshallerFactory()->createMarshaller($associationValidityConstraintElt);
                            $component->addAssociationValidityConstraint($marshaller->unmarshall($associationValidityConstraintElt));
                        }
                        
                        return $component;
                    } catch (InvalidArgumentException $e) {
                        throw new UnmarshallingException(
                            "An error occured while unmarshalling a 'responseValidityConstraint'. See chained exceptions for more information.",
                            $element,
                            $e
                        );
                    }
                    
                } else {
                    throw new UnmarshallingException(
                        "The mandatory 'maxConstraint' attribute is missing from element 'responseValididtyConstraint'.",
                        $element
                    );
                }
            } else {
                throw new UnmarshallingException(
                    "The mandatory 'minConstraint' attribute is missing from element 'responseValididtyConstraint'.",
                    $element
                );
            }
        } else {
            throw new UnmarshallingException(
                "The mandatory 'responseIdentifier' attribute is missing from element 'responseValididtyConstraint'.",
                $element
            );
        }
    }
999277
protected function getPropertyCache(\DOMElement $element)
    {
        $elementHash = $element->getNodePath();
        return isset($this->propertyCache[$elementHash]) ? $this->propertyCache[$elementHash] : null;
    }
847792
protected function exportHtml(\DOMElement $element)
    {
        $body = $this->getDocument()->createElement('body');
        $body->appendChild($element);
        $html = $this->getDocument()->getElementsByTagName('html')->item(0);
        $html->appendChild($this->getHead());
        $html->appendChild($body);

        $html =  $this->getDocument()->saveHTML();
        $this->reset();

        return $html;
    }
975214
protected function processGenerate($element, $data)
    {
        $this->prepareElementName($element);

        /** setRootName(null) support */
        if('' === (string) $element)
        {
            $element = array_keys($data)[0];

            return $this->processGenerate($element, $data[$element]);
        }

        /** @var \DOMElement $node */
        $node = $this->getDomDocument()->createElement($element);

        if(is_array($data))
        {
            $this->applyAttributes($data, $node);

            if(isset($data['@value']))
            {
                $this->applyValue($data, $node);

                return $node;
            }
            elseif(isset($data['@cdata']))
            {
                $this->applyCData($data, $node);

                return $node;
            }
            elseif(isset($data['@ns']))
            {
                $this->applyNamespace($data, $node);
            }
        }

        if(is_array($data))
        {
            foreach($data as $key => $value)
            {
                $this->prepareElementName($key);

                if('' === $key || false === $this->isValidElementName($key))
                {
                    continue;
                }

                if(is_array($value) && is_numeric(key($value)))
                {
                    foreach($value as $k => $v)
                    {
                        $node->appendChild($this->processGenerate($key, $v));
                    }
                }
                else
                {
                    $node->appendChild($this->processGenerate($key, $value));
                }

                unset($data[$key]);
            }
        }

        if(!is_array($data))
        {
            $data = $this->getBooleanAsString($data);

            $node->appendChild(
                $this->getDomDocument()->createTextNode($data)
            );
        }

        return $node;
    }
800688
public function toXML(DOMElement $parent = null) : DOMElement
    {
        $element = parent::toXML($parent);

        if ($this->Format !== null) {
            $element->setAttribute('Format', $this->Format);
        }

        if ($this->SPProvidedID !== null) {
            $element->setAttribute('SPProvidedID', $this->SPProvidedID);
        }

        $value = $element->ownerDocument->createTextNode($this->value);
        $element->appendChild($value);

        return $element;
    }
104889
protected function replaceElement(DOMElement $element)
	{
		$elName = $this->lowercase($element->localName);
		if ($elName === $element->localName)
		{
			return;
		}

		// Create a new element with the correct name
		$newElement = (is_null($element->namespaceURI))
		            ? $this->ownerDocument->createElement($elName)
		            : $this->ownerDocument->createElementNS($element->namespaceURI, $elName);

		// Move every child to the new element
		while ($element->firstChild)
		{
			$newElement->appendChild($element->removeChild($element->firstChild));
		}

		// Copy attributes to the new node
		foreach ($element->attributes as $attribute)
		{
			$newElement->setAttributeNS(
				$attribute->namespaceURI,
				$attribute->nodeName,
				$attribute->value
			);
		}

		// Replace the old element with the new one
		$element->parentNode->replaceChild($newElement, $element);
	}
284402
protected function isTangler(DOMElement $element, DOMNode $node)
    {
        return
            !isset($this->containmentMap[$node->localName][$element->localName])
            || ($node instanceof DOMElement && $node->hasAttribute(static::ATTRIBUTE_INHERIT_TANGLEMENT))
        ;
    }
290334
public function parseElement(Node $parent, \DOMElement $element)
    {
        if (Atom::NS !== $element->namespaceURI) {
            return null;
        }

        $name = 'atom:' . $element->localName;
        if (array_key_exists($name, $this->elementMap)) {
            $class = $this->elementMap[$name];

            return new $class($parent, $element);
        }

        return null;
    }
607309
private function convertElement(\DOMElement $element, $value)
    {
        if (! is_array($value)) {
            $value = htmlspecialchars(static::convertToString($value));
            $element->nodeValue = $value;

            return;
        }

        foreach ($value as $key => $data) {
            $child = $this->document->createElement($key);
            $element->appendChild($child);
            $this->convertElement($child, $data);
        }
    }
1098406
protected function cloneAndEmpty(DOMElement $element)
    {
        $clone = $element->cloneNode(true);

        $children = [];

        // Collect child nodes first, as we can't iterate and
        // remove from \DOMNodeList directly
        foreach ($clone->childNodes as $node) {
            $children[] = $node;
        }

        foreach ($children as $node) {
            $clone->removeChild($node);
        }

        return $clone;
    }
1320875
static public function changeElementName(DOMElement $element, $name)
    {
        $newElement = $element->ownerDocument->createElement($name);

        foreach ($element->childNodes as $child) {
            $child = $element->ownerDocument->importNode($child, true);
            $newElement->appendChild($child);
        }

        foreach ($element->attributes as $attrName => $attrNode) {
            if ($attrNode->namespaceURI === null) {
                $newElement->setAttribute($attrName, $attrNode->value);
            } else {
                $newElement->setAttributeNS($attrNode->namespaceURI, $attrNode->prefix . ':' . $attrName, $attrNode->value);
            }

        }

        $newElement->ownerDocument->replaceChild($newElement, $element);

        return $newElement;
    }
1025713
private function getFormNode(\DOMElement $element)
    {
        if ($element->hasAttribute('form')) {
            $formId = $element->getAttribute('form');
            $formNode = $element->ownerDocument->getElementById($formId);

            if (null === $formNode || 'form' !== $formNode->nodeName) {
                throw new DriverException(sprintf('The selected node has an invalid form attribute (%s).', $formId));
            }

            return $formNode;
        }

        $formNode = $element;

        do {
            // use the ancestor form element
            if (null === $formNode = $formNode->parentNode) {
                throw new DriverException('The selected node does not have a form ancestor.');
            }
        } while ('form' !== $formNode->nodeName);

        return $formNode;
    }