i have a long xml containing information that i need to import them into my mysql database.
to do so i write some sql queries with php language
i faced some problem with empty tags [bug with php5 and xml)
to resolve this bug, i writed an xslt file to remove the empty file.
the code is working fine in case of small xml file.
but when i apply the same code on a long and big xml file, it takes time and i didnt get any result (break code)
my code is
Expand|Select|Wrap|Line Numbers
- public function loadXML(){
- $path = Yii::getPathOfAlias('webroot') . '/protected/files/';
- $filename = $path . 'loads.xml'; // the source xml file that contains the SIS information
- $xsltFile = $path . 'clean.xsl'; // the xslt file that contains the xslt code that remove the empty tags
- //$result = $path . 'test.xml'; // the output result file: SIS xml file without the empty tags
- $result = $path . 'loads.xml'; // the output result file: SIS xml file without the empty tags
- // because the empty tags cause to insert empty and NULL values into database
- // ------- run the xslt file that remove the empty element from the xml source file that contains the SIS information --------
- // Load the XML source
- $xml = new DOMDocument;
- $xml->load($filename);
- $xsl = new DOMDocument;
- $xsl->load($xsltFile);
- // Configure the transformer
- $proc = new XSLTProcessor;
- $proc->importStyleSheet($xsl); // attach the xsl rules
- if ($xml_output = $proc->transformToXML($xml)) {
- file_put_contents($result, $xml_output);
- } else {
- trigger_error('Oops, XSLT transformation failed!', E_USER_ERROR);
- }
- // --------------------------------------------------------------------------------------------------------------------------------
- $sql='LOAD XML INFILE \'' . $result . '\' INTO TABLE stclass ROWS IDENTIFIED BY "<VwClass>"';
- Yii::app()->db->createCommand($sql)->execute();
- /*
- $sql='LOAD XML INFILE \'' . $result . '\' INTO TABLE matiere ROWS IDENTIFIED BY "<vwClassSubjects>"';
- Yii::app()->db->createCommand($sql)->execute();
- $sql='LOAD XML INFILE \'' . $result . '\' INTO TABLE student ROWS IDENTIFIED BY "<VwRegisteredStudents>"';
- Yii::app()->db->createCommand($sql)->execute();
- $sql='LOAD XML INFILE \'' . $result . '\' INTO TABLE usersectionsecurity ROWS IDENTIFIED BY "<vwUserSectionSecurity>"';
- Yii::app()->db->createCommand($sql)->execute();*/
- }
the xml file size is 216.336 KB