I was moving a WP from a host to another, and using the WordPress Importer while loading the XML of the export “Fatal error: Class ‘DOMDocument’ not found“.
We have two solutions
- Install the php-xml package on your server.
- Replace in file parsers.php in plugin wordpress-importer at class WXR_Parser_SimpleXML
Replace in file parsers.php in plugin wordpress-importer at Class WXR_Parser_SimpleXML
Change
$dom = new DOMDocument; $old_value = null; if ( function_exists( 'libxml_disable_entity_loader' ) ) { $old_value = libxml_disable_entity_loader( true ); } $success = $dom->loadXML( file_get_contents( $file ) ); if ( ! is_null( $old_value ) ) { libxml_disable_entity_loader( $old_value ); }if ( ! $success || isset( $dom->doctype ) ) { return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'wordpress-importer' ), libxml_get_errors() ); }$xml = simplexml_import_dom( $dom ); unset( $dom );
For:
$xml = simplexml_load_file($file);