function testWithNameSpaceParser()
 {
     $parser = new DocTypeNameSpaceXMLParser();
     if ($parser->parseFile(dirname(__FILE__) . '/resources/FileWithNameSpace.xml')) {
         $this->assertEquals('Items', $parser->getDocType());
         $this->assertEquals('http://opendb.iamvegan.net/xsd/Items-1.3.xsd', $parser->getNameSpace());
     } else {
         print_r($parser->getErrors());
         $this->assertTrue(false);
     }
 }
Example #2
0
/**
Will return the plugin to use, based on the $http_post_uploadfile_r['name']
and/or the start of the file itself (available via: $http_post_uploadfile_r['tmp_name'])
*/
function &get_import_plugin_from_uploadfile($http_post_uploadfile_r, &$error)
{
    $extension = strtolower(get_file_ext($http_post_uploadfile_r['name']));
    if (strlen($extension) > 0) {
        if ($extension == 'xml') {
            // We need to find the DOCTYPE for the XML file, so we can assign an XML plugin.
            if (function_exists('xml_parser_create')) {
                if (file_exists($http_post_uploadfile_r['tmp_name'])) {
                    $xmlParser = new DocTypeNameSpaceXMLParser();
                    if ($xmlParser->parseFile($http_post_uploadfile_r['tmp_name'])) {
                        $docType = $xmlParser->getDocType();
                        $nameSpace = $xmlParser->getNameSpace();
                        unset($xmlParser);
                        if (strlen($docType) > 0) {
                            $importPlugin =& get_import_plugin_for_extension($extension, $docType, $nameSpace);
                            if ($importPlugin !== NULL) {
                                return $importPlugin;
                            } else {
                                $error = get_opendb_lang_var('doctype_not_supported', 'doctype', $docType);
                                return NULL;
                            }
                        } else {
                            $error = get_opendb_lang_var('no_doctype_found');
                            return NULL;
                        }
                    } else {
                        $error = get_opendb_lang_var('file_upload_error');
                        return NULL;
                    }
                } else {
                    $error = get_opendb_lang_var('file_upload_error');
                    return NULL;
                }
            } else {
                $error = get_opendb_lang_var('xml_import_plugins_not_supported');
                return NULL;
            }
        } else {
            $importPlugin =& get_import_plugin_for_extension($extension);
            if ($importPlugin !== NULL) {
                return $importPlugin;
            } else {
                $error = get_opendb_lang_var('extension_not_supported', 'extension', strtoupper($extension));
                return NULL;
            }
        }
    } else {
        $error = get_opendb_lang_var('no_extension_found');
        return NULL;
    }
}