public static function sanitizeQtiXml($qti)
    {
        $doc = self::loadQtiXml($qti);
        
        $xpath = new \DOMXpath($doc);
        
        foreach ($xpath->query("//*[local-name() = 'itemBody']//*[@style]") as $elementWithStyle) {
            $elementWithStyle->removeAttribute('style');
        }

        $ids = array();
        /** @var \DOMElement $elementWithId */
        foreach ($xpath->query("//*[not(local-name()='lib') and not(local-name()='module') and @id]") as $elementWithId) {
            $id = $elementWithId->getAttribute('id');
            if(in_array($id, $ids)){
                $elementWithId->removeAttribute('id');
            } else{
                $ids[] = $id;
            }
        }

        return $doc->saveXML();
    }
public static function sanitizeQtiXml($qti)
    {
        $doc = self::loadQtiXml($qti);
        
        $xpath = new \DOMXpath($doc);
        
        foreach ($xpath->query("//*[local-name() = 'itemBody']//*[@style]") as $elementWithStyle) {
            $elementWithStyle->removeAttribute('style');
        }

        $ids = array();
        /** @var \DOMElement $elementWithId */
        foreach ($xpath->query("//*[not(local-name()='lib') and not(local-name()='module') and @id]") as $elementWithId) {
            $id = $elementWithId->getAttribute('id');
            if(in_array($id, $ids)){
                $elementWithId->removeAttribute('id');
            } else{
                $ids[] = $id;
            }
        }

        return $doc->saveXML();
    }
public static function sanitizeQtiXml ( $ qti ) { $ doc = self :: loadQtiXml ( $ qti ) ; $ xpath = new \ DOMXpath ( $ doc ) ; foreach ( $ xpath -> query ( "//*[local-name() = 'itemBody']//*[@style]" ) as $ elementWithStyle ) { $ elementWithStyle -> removeAttribute ( 'style' ) ; } $ ids = array ( ) ; /** @var \DOMElement $elementWithId */ foreach ( $ xpath -> query ( "//*[not(local-name()='lib') and not(local-name()='module') and @id]" ) as $ elementWithId ) { $ id = $ elementWithId -> getAttribute ( 'id' ) ; if ( in_array ( $ id , $ ids ) ) { $ elementWithId -> removeAttribute ( 'id' ) ; } else { $ ids [ ] = $ id ; } } return $ doc -> saveXML ( ) ; }
Remove invalid elements and attributes from QTI XML.
@param string $qti File path or XML string
@return string sanitized XML
Remove invalid elements and attributes from QTI XML .