createDomDocument($sharedStimulus); $xinclude = $this->createXInclude($document); $this->addLanguageAttribute($document, $xinclude); return $xinclude->toArray(); } private function createDomDocument(SharedStimulus $sharedStimulus): DOMDocument { $content = $sharedStimulus->getBody(); if (empty($content)) { throw new LogicException('SharedStimulus content is empty and cannot be parsed.'); } $document = new DOMDocument(); $document->loadXML($content, LIBXML_BIGLINES | LIBXML_PARSEHUGE); return $document; } private function createXInclude(DOMDocument $document): XInclude { return $this->hydrateXInclude(new XInclude(), $document); } private function hydrateXInclude(XInclude $xinclude, DOMDocument $document): XInclude { $parser = new ParserFactory($document); $parser->loadContainerStatic($document->firstChild, $xinclude->getBody()); return $xinclude; } /** * @throws QtiModelException */ private function addLanguageAttribute(DOMDocument $document, XInclude $xinclude): void { if (isset($document->getElementsByTagName('div')->item(0)->attributes['lang']->nodeValue)) { $xinclude->setAttribute( 'xml:lang', $document->getElementsByTagName('div')->item(0)->attributes['lang']->nodeValue ); } } }