public static function loadQtiXml($file) 
    {
        if ($file instanceof File) {
            $qti = $file->read();
        } else if (preg_match("/^<\?xml(.*)?/m", trim($file))) {
            $qti = $file;
        } else if (is_file($file)) {
            $qti = file_get_contents($file);
        } else {
            throw new \common_exception_Error("Wrong parameter. " . __CLASS__ . "::" . __METHOD__ . " accepts either XML content or the path to a file but got ".substr($file, 0, 500));
        }
        
        $dom = new DOMDocument('1.0', 'UTF-8');

        $domDocumentConfig = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem')->getConfig('XMLParser');

        if (is_array($domDocumentConfig) && !empty($domDocumentConfig)) {
            foreach ($domDocumentConfig as $param => $value) {
                if (property_exists($dom, $param)) {
                    $dom->$param = $value;
                }
            }
        } else {
            $dom->formatOutput = true;
            $dom->preserveWhiteSpace = false;
            $dom->validateOnParse = false;
        }
        
        libxml_use_internal_errors(true);
        
        if (!$dom->loadXML($qti)) {
            $errors = libxml_get_errors();
            
            $errorsMsg = 'Wrong QTI item output format:' 
            . PHP_EOL 
            . array_reduce($errors, function ($carry, $item) {
                $carry .= $item->message . PHP_EOL;
                return $carry;
            });
            
            common_Logger::w($errorsMsg);
            
            throw new QtiModelException($errorsMsg);
        }
        
        return $dom;
    }
public static function loadQtiXml($file) 
    {
        if ($file instanceof File) {
            $qti = $file->read();
        } else if (preg_match("/^<\?xml(.*)?/m", trim($file))) {
            $qti = $file;
        } else if (is_file($file)) {
            $qti = file_get_contents($file);
        } else {
            throw new \common_exception_Error("Wrong parameter. " . __CLASS__ . "::" . __METHOD__ . " accepts either XML content or the path to a file but got ".substr($file, 0, 500));
        }
        
        $dom = new DOMDocument('1.0', 'UTF-8');

        $domDocumentConfig = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem')->getConfig('XMLParser');

        if (is_array($domDocumentConfig) && !empty($domDocumentConfig)) {
            foreach ($domDocumentConfig as $param => $value) {
                if (property_exists($dom, $param)) {
                    $dom->$param = $value;
                }
            }
        } else {
            $dom->formatOutput = true;
            $dom->preserveWhiteSpace = false;
            $dom->validateOnParse = false;
        }
        
        libxml_use_internal_errors(true);
        
        if (!$dom->loadXML($qti)) {
            $errors = libxml_get_errors();
            
            $errorsMsg = 'Wrong QTI item output format:' 
            . PHP_EOL 
            . array_reduce($errors, function ($carry, $item) {
                $carry .= $item->message . PHP_EOL;
                return $carry;
            });
            
            common_Logger::w($errorsMsg);
            
            throw new QtiModelException($errorsMsg);
        }
        
        return $dom;
    }
public static function loadQtiXml ( $ file ) { if ( $ file instanceof File ) { $ qti = $ file -> read ( ) ; } else if ( preg_match ( "/^<\?xml(.*)?/m" , trim ( $ file ) ) ) { $ qti = $ file ; } else if ( is_file ( $ file ) ) { $ qti = file_get_contents ( $ file ) ; } else { throw new \ common_exception_Error ( "Wrong parameter. " . __CLASS__ . "::" . __METHOD__ . " accepts either XML content or the path to a file but got " . substr ( $ file , 0 , 500 ) ) ; } $ dom = new DOMDocument ( '1.0' , 'UTF-8' ) ; $ domDocumentConfig = \ common_ext_ExtensionsManager :: singleton ( ) -> getExtensionById ( 'taoQtiItem' ) -> getConfig ( 'XMLParser' ) ; if ( is_array ( $ domDocumentConfig ) && ! empty ( $ domDocumentConfig ) ) { foreach ( $ domDocumentConfig as $ param => $ value ) { if ( property_exists ( $ dom , $ param ) ) { $ dom -> $ param = $ value ; } } } else { $ dom -> formatOutput = true ; $ dom -> preserveWhiteSpace = false ; $ dom -> validateOnParse = false ; } libxml_use_internal_errors ( true ) ; if ( ! $ dom -> loadXML ( $ qti ) ) { $ errors = libxml_get_errors ( ) ; $ errorsMsg = 'Wrong QTI item output format:' . PHP_EOL . array_reduce ( $ errors , function ( $ carry , $ item ) { $ carry .= $ item -> message . PHP_EOL ; return $ carry ; } ) ; common_Logger :: w ( $ errorsMsg ) ; throw new QtiModelException ( $ errorsMsg ) ; } return $ dom ; }
Load QTI xml and return DOMDocument instance.
If string is not valid xml then QtiModelException will be thrown.

@param string|File $file If it's a string it can be a file path or an XML string
@throws QtiModelException
@throws common_exception_Error
@return DOMDocument
Load QTI xml and return DOMDocument instance . If string is not valid xml then QtiModelException will be thrown .