public function getXml()
    {
        // Build the DOMDocument object only on demand.
        if ($this->xml === null) {

            $xml = new SerializableDomDocument('1.0', 'UTF-8');
            if (@$xml->loadXML($this->getXmlString()) === false) {
                $msg = "The XML content '" . $this->getXmlString() . "' of the '" . $this->getQtiClassName() . "' external component could not be parsed correctly.";
                throw new RuntimeException($msg);
            }

            if (($targetNamespace = $this->getTargetNamespace()) !== '' && $xml->documentElement->namespaceURI !== $this->getTargetNamespace()) {
                $msg = "The XML content' " . $this->getXmlString() . "' of the '" . $this->getQtiClassName() . "' external component is not referenced into target namespace '" . $this->getTargetNamespace() . "'.";
                throw new RuntimeException($msg);
            }

            $this->setXml($xml);
        }

        return $this->xml;
    }