Index: src/edu/ucsb/nceas/metacat/DocumentImpl.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DocumentImpl.java	(revision 9955)
+++ src/edu/ucsb/nceas/metacat/DocumentImpl.java	(revision 9956)
@@ -114,6 +114,7 @@
     public static final String EML200 = "eml200";
     public static final String EML210 = "eml210";
     public static final String EXTERNALSCHEMALOCATIONPROPERTY = "http://apache.org/xml/properties/schema/external-schemaLocation";
+    public static final String EXTERNALNONAMESPACESCHEMALOCATIONPROPERTY = "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation";
     public static final String REVISIONTABLE = "xml_revisions";
     public static final String DOCUMENTTABLE = "xml_documents";
     /*
@@ -2658,7 +2659,7 @@
 
     public static String write(DBConnection conn, String xmlString, String pub,
             Reader dtd, String action, String docid, String user,
-            String[] groups, String ruleBase, boolean needValidation, boolean writeAccessRules, byte[] xmlBytes, String formatId)
+            String[] groups, String ruleBase, boolean needValidation, boolean writeAccessRules, byte[] xmlBytes, String schemaLocation)
             throws Exception
     {
         //this method will be called in handleUpdateOrInsert method
@@ -2666,7 +2667,7 @@
         // get server location for this doc
         int serverLocation = getServerLocationNumber(docid);
         return write(conn, xmlString, pub, dtd, action, docid, user, groups,
-                serverLocation, false, ruleBase, needValidation, writeAccessRules, xmlBytes, formatId);
+                serverLocation, false, ruleBase, needValidation, writeAccessRules, xmlBytes, schemaLocation);
     }
 
     /**
@@ -2703,7 +2704,7 @@
     public static String write(DBConnection conn, String xmlString, String pub,
             Reader dtd, String action, String accnum, String user,
             String[] groups, int serverCode, boolean override, String ruleBase,
-            boolean needValidation, boolean writeAccessRules, byte[] xmlBytes, String formatId) throws Exception
+            boolean needValidation, boolean writeAccessRules, byte[] xmlBytes, String schemaLocation) throws Exception
     {
         // NEW - WHEN CLIENT ALWAYS PROVIDE ACCESSION NUMBER INCLUDING REV IN IT
     	
@@ -2790,7 +2791,7 @@
                     logMetacat.debug("DocumentImpl.write - initializing parser");
                     parser = initializeParser(conn, action, docid, xmlReader, updaterev,
                             user, groups, pub, serverCode, dtd, ruleBase,
-                            needValidation, false, null, null, encoding, writeAccessRules, guidsToSync, formatId);
+                            needValidation, false, null, null, encoding, writeAccessRules, guidsToSync, schemaLocation);
                     	// false means it is not a revision doc
                                    //null, null are createdate and updatedate
                                    //null will use current time as create date time
@@ -2894,13 +2895,13 @@
 	        Vector<String>guidsToSync = new Vector<String>();
 
             parser = initializeParser(conn, action, docid, xmlReader, rev, user, groups,
-                    pub, serverCode, dtd, ruleBase, needValidation, false, null, null, encoding, writeAccessRules, guidsToSync, formatId);
+                    pub, serverCode, dtd, ruleBase, needValidation, false, null, null, encoding, writeAccessRules, guidsToSync, schemaLocation);
                     // null and null are createtime and updatetime
                     // null will create current time
                     //false means it is not a revision doc
 
             conn.setAutoCommit(false);
-            logMetacat.debug("DocumentImpl.write - XML to be parsed: " + xmlString);
+            //logMetacat.debug("DocumentImpl.write - XML to be parsed: " + xmlString);
             parser.parse(new InputSource(xmlReader));
 
             conn.commit();
@@ -3038,7 +3039,7 @@
             String pub, Reader dtd, String action, String accnum, String user,
             String[] groups, String homeServer, String notifyServer,
             String ruleBase, boolean needValidation, String tableName, 
-            boolean timedReplication, Date createDate, Date updateDate, String formatId) throws Exception
+            boolean timedReplication, Date createDate, Date updateDate, String schemaLocation) throws Exception
     {
     	// Get the xml as a string so we can write to file later
     	StringReader xmlReader = new StringReader(xmlString);
@@ -3106,7 +3107,7 @@
 
             parser = initializeParser(conn, action, docid, xmlReader, rev, user, groups,
                     pub, serverCode, dtd, ruleBase, needValidation, 
-                    isRevision, createDate, updateDate, encoding, writeAccessRules, guidsToSync, formatId);
+                    isRevision, createDate, updateDate, encoding, writeAccessRules, guidsToSync, schemaLocation);
          
             conn.setAutoCommit(false);
             parser.parse(new InputSource(xmlReader));
@@ -3725,7 +3726,7 @@
             String action, String docid, Reader xml, String rev, String user,
             String[] groups, String pub, int serverCode, Reader dtd,
             String ruleBase, boolean needValidation, boolean isRevision,
-            Date createDate, Date updateDate, String encoding, boolean writeAccessRules, Vector<String> guidsToSync, String formatId) throws Exception
+            Date createDate, Date updateDate, String encoding, boolean writeAccessRules, Vector<String> guidsToSync, String schemaLocation) throws Exception
     {
         XMLReader parser = null;
         try {
@@ -3736,7 +3737,7 @@
             // Get an instance of the parser
             String parserName = PropertyService.getProperty("xml.saxparser");
             parser = XMLReaderFactory.createXMLReader(parserName);
-            XMLSchemaService.getInstance().populateRegisteredSchemaList();
+            //XMLSchemaService.getInstance().populateRegisteredSchemaList();
             if (ruleBase != null && ruleBase.equals(EML200)) {
                 logMetacat.info("DocumentImpl.initalizeParser - Using eml 2.0.0 parser");
                 chandler = new Eml200SAXHandler(dbconn, action, docid, rev,
@@ -3747,32 +3748,25 @@
                 parser.setErrorHandler((ErrorHandler) chandler);
                 parser.setProperty(DECLARATIONHANDLERPROPERTY, chandler);
                 parser.setProperty(LEXICALPROPERTY, chandler);
-                // turn on schema validation feature
-                parser.setFeature(VALIDATIONFEATURE, true);
                 parser.setFeature(NAMESPACEFEATURE, true);
-                //parser.setFeature(NAMESPACEPREFIXESFEATURE, true);
-                parser.setFeature(SCHEMAVALIDATIONFEATURE, true);
-                // From DB to find the register external schema location
-                String externalSchemaLocation = null;
-//                SchemaLocationResolver resolver = new SchemaLocationResolver();
-                logMetacat.debug("DocumentImpl.initalizeParser - the final formatId of the object "+docid+" is "+formatId);
-                externalSchemaLocation = XMLSchemaService.getInstance().getNameSpaceAndLocation(formatId);
-                if(externalSchemaLocation == null) {
-                    logMetacat.info("DocumentImpl.initalizeParser - there is no register schemas for the formatid "+ formatId+". So we will use the old way."+
-                    " Put all registred schema/location paris for the validation.");
-                    externalSchemaLocation = XMLSchemaService.getInstance().getNameSpaceAndLocationStringWithoutFormatId();
-                    
-                } 
-                logMetacat.info("DocumentImpl.initalizeParser - 2.0.0 external schema location: " + externalSchemaLocation);
-                // Set external schemalocation.
-                if (externalSchemaLocation != null
-                        && !(externalSchemaLocation.trim()).equals("")) {
-                    parser.setProperty(EXTERNALSCHEMALOCATIONPROPERTY,
-                            externalSchemaLocation);
-                } else {
-                    throw new Exception ("The schema for the format id "+formatId+" can't be found in any place. So we can't validate the xml instance.");
+                if(needValidation) {
+                    logMetacat.info("DocumentImpl.initalizeParser - 2.0.0 parser sets up validation feature since the parameter of the needValidataion is "+needValidation);
+                    // turn on schema validation feature
+                    parser.setFeature(VALIDATIONFEATURE, true);
+                    //parser.setFeature(NAMESPACEPREFIXESFEATURE, true);
+                    parser.setFeature(SCHEMAVALIDATIONFEATURE, true);
+                    logMetacat.info("DocumentImpl.initalizeParser - 2.0.0 external schema location: " + schemaLocation);
+                    // Set external schemalocation.
+                    if (schemaLocation != null
+                            && !(schemaLocation.trim()).equals("")) {
+                        parser.setProperty(EXTERNALSCHEMALOCATIONPROPERTY,
+                                schemaLocation);
+                    } else {
+                        throw new Exception ("The schema for the namespace on docid "+docid+" can't be found in any place. So we can't validate the xml instance.");
+                    }
                 }
-                logMetacat.debug("DocumentImpl.initalizeParser - 2.0.0 parser configured");
+                
+                logMetacat.info("DocumentImpl.initalizeParser - 2.0.0 parser configured");
             } else if (ruleBase != null && ruleBase.equals(EML210)) {
                 logMetacat.info("DocumentImpl.initalizeParser - Using eml 2.1.0 parser");
                 chandler = new Eml210SAXHandler(dbconn, action, docid, rev,
@@ -3784,28 +3778,21 @@
                 parser.setProperty(DECLARATIONHANDLERPROPERTY, chandler);
                 parser.setProperty(LEXICALPROPERTY, chandler);
                 // turn on schema validation feature
-                parser.setFeature(VALIDATIONFEATURE, true);
                 parser.setFeature(NAMESPACEFEATURE, true);
-                //parser.setFeature(NAMESPACEPREFIXESFEATURE, true);
-                parser.setFeature(SCHEMAVALIDATIONFEATURE, true);
-                // From DB to find the register external schema location
-                String externalSchemaLocation = null;
-                logMetacat.debug("DocumentImpl.initalizeParser - the final formatId of the object "+docid+" is "+formatId);
-                externalSchemaLocation = XMLSchemaService.getInstance().getNameSpaceAndLocation(formatId);
-                if(externalSchemaLocation == null) {
-                    logMetacat.info("DocumentImpl.initalizeParser - there is no register schemas for the formatid "+ formatId+". So we will use the old way."+
-                    " Put all registred schema/location paris for the validation.");
-                    externalSchemaLocation = XMLSchemaService.getInstance().getNameSpaceAndLocationStringWithoutFormatId();
-                    
-                } 
-                logMetacat.info("DocumentImpl.initalizeParser - 2.1.0 external schema location: " + externalSchemaLocation);
-                // Set external schemalocation.
-                if (externalSchemaLocation != null
-                        && !(externalSchemaLocation.trim()).equals("")) {
-                    parser.setProperty(EXTERNALSCHEMALOCATIONPROPERTY,
-                            externalSchemaLocation);
-                } else {
-                    throw new Exception ("The schema for the format id "+formatId+" can't be found in any place. So we can't validate the xml instance.");
+                if(needValidation) {
+                    logMetacat.info("DocumentImpl.initalizeParser - 2.1.0 parser sets up validation features since the parameter of the needValidataion is "+needValidation);
+                    parser.setFeature(VALIDATIONFEATURE, true);
+                    //parser.setFeature(NAMESPACEPREFIXESFEATURE, true);
+                    parser.setFeature(SCHEMAVALIDATIONFEATURE, true);
+                    logMetacat.info("DocumentImpl.initalizeParser - 2.1.0 external schema location: " + schemaLocation);
+                    // Set external schemalocation.
+                    if (schemaLocation != null
+                            && !(schemaLocation.trim()).equals("")) {
+                        parser.setProperty(EXTERNALSCHEMALOCATIONPROPERTY,
+                                schemaLocation);
+                    } else {
+                        throw new Exception ("The schema for the docid "+docid+" can't be found in any place. So we can't validate the xml instance.");
+                    }
                 }
                 logMetacat.debug("DocumentImpl.initalizeParser - Using eml 2.1.0 parser configured");
             } else {
@@ -3824,7 +3811,7 @@
                         && needValidation) {
                 
                     XMLSchemaService xmlss = XMLSchemaService.getInstance();
-                    xmlss.doRefresh();
+                    //xmlss.doRefresh();
                     logMetacat.info("DocumentImpl.initalizeParser - Using General schema parser");
                     // turn on schema validation feature
                     parser.setFeature(VALIDATIONFEATURE, true);
@@ -3838,26 +3825,33 @@
                     if (xmlss.useFullSchemaValidation() && !allSchemasRegistered) {
                     	parser.setFeature(FULLSCHEMAVALIDATIONFEATURE, true);
                     }
-                    // From DB to find the register external schema location
-                    String externalSchemaLocation = null;
-                    logMetacat.debug("DocumentImpl.initalizeParser - the final formatId of the object "+docid+" is "+formatId);
-                    externalSchemaLocation = XMLSchemaService.getInstance().getNameSpaceAndLocation(formatId);
-                    if(externalSchemaLocation == null) {
-                        logMetacat.info("DocumentImpl.initalizeParser - there is no register schemas for the formatid "+ formatId+". So we will use the old way."+
-                        " Put all registred schema/location paris for the validation.");
-                        externalSchemaLocation = XMLSchemaService.getInstance().getNameSpaceAndLocationStringWithoutFormatId();
-                        
-                    } 
-                    logMetacat.info("DocumentImpl.initalizeParser - Generic external schema location: " + externalSchemaLocation);              
+                    logMetacat.info("DocumentImpl.initalizeParser - Generic external schema location: " + schemaLocation);              
                     // Set external schemalocation.
-                    if (externalSchemaLocation != null
-                            && !(externalSchemaLocation.trim()).equals("")) {
+                    if (schemaLocation != null
+                            && !(schemaLocation.trim()).equals("")) {
                         parser.setProperty(EXTERNALSCHEMALOCATIONPROPERTY,
-                                externalSchemaLocation);
+                                schemaLocation);
                     } else {
-                        throw new Exception ("The schema for the format id "+formatId+" can't be found in any place. So we can't validate the xml instance.");
+                        throw new Exception ("The schema for the document "+docid+" can't be found in any place. So we can't validate the xml instance.");
                     }
-
+                } else if (ruleBase != null && ruleBase.equals(NONAMESPACESCHEMA)
+                        && needValidation) {
+                    //xmlss.doRefresh();
+                    logMetacat.info("DocumentImpl.initalizeParser - Using General schema parser");
+                    // turn on schema validation feature
+                    parser.setFeature(VALIDATIONFEATURE, true);
+                    parser.setFeature(NAMESPACEFEATURE, true);
+                    //parser.setFeature(NAMESPACEPREFIXESFEATURE, true);
+                    parser.setFeature(SCHEMAVALIDATIONFEATURE, true);
+                    logMetacat.info("DocumentImpl.initalizeParser - Generic external no-namespace schema location: " + schemaLocation);              
+                    // Set external schemalocation.
+                    if (schemaLocation != null
+                            && !(schemaLocation.trim()).equals("")) {
+                        parser.setProperty(EXTERNALNONAMESPACESCHEMALOCATIONPROPERTY,
+                                schemaLocation);
+                    } else {
+                        throw new Exception ("The schema for the document "+docid+" can't be found in any place. So we can't validate the xml instance.");
+                    }
                 } else if (ruleBase != null && ruleBase.equals(DTD)
                         && needValidation) {
                     logMetacat.info("DocumentImpl.initalizeParser - Using dtd parser");
Index: src/edu/ucsb/nceas/metacat/DocumentImplWrapper.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DocumentImplWrapper.java	(revision 9955)
+++ src/edu/ucsb/nceas/metacat/DocumentImplWrapper.java	(revision 9956)
@@ -59,9 +59,9 @@
 	}//Constructor
 
 	public String write(DBConnection conn, String xml, String pub, Reader dtd,
-			String action, String docid, String user, String[] groups, byte[]xmlBytes, String formatId) throws Exception {
+			String action, String docid, String user, String[] groups, byte[]xmlBytes, String schemaLocalLocation) throws Exception {
 		return DocumentImpl.write(conn, xml, pub, dtd, action, docid, user, groups,
-				ruleBase, needValidation, writeAccessRules, xmlBytes, formatId);
+				ruleBase, needValidation, writeAccessRules, xmlBytes, schemaLocalLocation);
 	}
 
 	public String writeReplication(DBConnection conn, String xml, byte[]xmlBytes, String pub, Reader dtd,
@@ -72,9 +72,11 @@
 		// so rule base is null and need validation is false (first false)
 		// this method is for force replication. so the table name is xml_documents
 		// and timed replication is false (last false)
+	    String schemaLocation = null;
+	    boolean needValidate = false;
 		return DocumentImpl.writeReplication(conn, xml, xmlBytes, pub, dtd, action, accnum, user,
-				groups, homeServer, notifyServer, ruleBase, false,
-				DocumentImpl.DOCUMENTTABLE, false, createDate, updateDate, formatId);
+				groups, homeServer, notifyServer, ruleBase, needValidate,
+				DocumentImpl.DOCUMENTTABLE, false, createDate, updateDate, schemaLocation);
 		// last false means is not timed replication
 
 	}
@@ -103,9 +105,11 @@
 			throws Exception {
 		//we don't need to check validation in replication
 		// so rule base is null and need validation is false
+	    String schemaLocation = null;
+	    boolean needValidate = false;
 		return DocumentImpl.writeReplication(conn, xml, xmlBytes, pub, dtd, action, accnum, user,
-				groups, homeServer, notifyServer, ruleBase, false, tableName,
-				timedReplication, createDate, updateDate, formatId);
+				groups, homeServer, notifyServer, ruleBase, needValidate, tableName,
+				timedReplication, createDate, updateDate, schemaLocation);
 	}
 
 }
Index: src/edu/ucsb/nceas/metacat/MetacatHandler.java
===================================================================
--- src/edu/ucsb/nceas/metacat/MetacatHandler.java	(revision 9955)
+++ src/edu/ucsb/nceas/metacat/MetacatHandler.java	(revision 9956)
@@ -1722,7 +1722,7 @@
           boolean validate = false;
           DocumentImplWrapper documentWrapper = null;
           String namespace = null;
-
+          String schemaLocation = null;
           try {
             // look inside XML Document for <!DOCTYPE ... PUBLIC/SYSTEM ...
             // >
@@ -1730,13 +1730,15 @@
             validate = needDTDValidation(xmlReader);
             if (validate) {
                 // set a dtd base validation parser
+                logMetacat.debug("MetacatHandler.handleInsertOrUpdateAction - the xml object will be validate by a dtd");
                 String rule = DocumentImpl.DTD;
                 documentWrapper = new DocumentImplWrapper(rule, validate, writeAccessRules);
             } else {
-                
+                XMLSchemaService.getInstance().doRefresh();
                 namespace = XMLSchemaService.findDocumentNamespace(xmlReader);
-                
                 if (namespace != null) {
+                    logMetacat.debug("MetacatHandler.handleInsertOrUpdateAction - the xml object will be validated by a schema which has a target namespace: "+namespace);
+                    schemaLocation = XMLSchemaService.getInstance().findNamespaceAndSchemaLocalLocation(formatId, namespace);
                     if (namespace.compareTo(DocumentImpl.EML2_0_0NAMESPACE) == 0
                             || namespace.compareTo(
                             DocumentImpl.EML2_0_1NAMESPACE) == 0) {
@@ -1756,12 +1758,26 @@
                         EMLParser parser = new EMLParser(doctext[0]);
                         documentWrapper = new DocumentImplWrapper(rule, true, writeAccessRules);
                     } else {
+                        if(!XMLSchemaService.isNamespaceRegistered(namespace)) {
+                            throw new Exception("The namespace "+namespace+" used in the xml object hasn't been registered in the Metacat. Metacat can't validate the object and rejected it. Please contact the operator of the Metacat for regsitering the namespace.");
+                        }
                         // set schema base validation parser
                         String rule = DocumentImpl.SCHEMA;
                         documentWrapper = new DocumentImplWrapper(rule, true, writeAccessRules);
                     }
                 } else {
-                    documentWrapper = new DocumentImplWrapper("", false, writeAccessRules);
+                    xmlReader = new StringReader(doctext[0]);
+                    String noNamespaceSchemaLocationAttr = XMLSchemaService.findNoNamespaceSchemaLocationAttr(xmlReader);
+                    if(noNamespaceSchemaLocationAttr != null) {
+                        logMetacat.debug("MetacatHandler.handleInsertOrUpdateAction - the xml object will be validated by a schema which deoe NOT have a target namespace.");
+                        schemaLocation = XMLSchemaService.getInstance().findNoNamespaceSchemaLocalLocation(formatId, noNamespaceSchemaLocationAttr);
+                        String rule = DocumentImpl.NONAMESPACESCHEMA;
+                        documentWrapper = new DocumentImplWrapper(rule, true, writeAccessRules);
+                    } else {
+                        logMetacat.debug("MetacatHandler.handleInsertOrUpdateAction - the xml object will NOT be validated.");
+                        documentWrapper = new DocumentImplWrapper("", false, writeAccessRules);
+                    }
+                    
                 }
             }
             
@@ -1805,7 +1821,7 @@
               
               } else {*/
               newdocid = documentWrapper.write(dbConn, doctext[0], pub, dtd,
-                          doAction, accNumber, user, groups, xmlBytes, formatId);
+                          doAction, accNumber, user, groups, xmlBytes, schemaLocation);
             
               EventLog.getInstance().log(ipAddress, userAgent, user, accNumber, action[0]);
               
@@ -1909,7 +1925,7 @@
             output += e.getMessage();
             output += this.ERRORCLOSE;
             logMetacat.warn("MetacatHandler.handleInsertOrUpdateAction - " +
-            		        "General error when writing eml " +
+            		        "General error when writing the xml object " +
             		        "document to the database: " + 
             		        e.getMessage());
             e.printStackTrace();
Index: src/edu/ucsb/nceas/metacat/util/EMLVersionsTransformer.java
===================================================================
--- src/edu/ucsb/nceas/metacat/util/EMLVersionsTransformer.java	(revision 9955)
+++ src/edu/ucsb/nceas/metacat/util/EMLVersionsTransformer.java	(revision 9956)
@@ -41,6 +41,7 @@
 import edu.ucsb.nceas.metacat.database.DBConnection;
 import edu.ucsb.nceas.metacat.database.DBConnectionPool;
 import edu.ucsb.nceas.metacat.properties.PropertyService;
+import edu.ucsb.nceas.metacat.service.XMLSchemaService;
 
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.Transformer;
@@ -49,6 +50,7 @@
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.URIResolver;
+
 import org.ecoinformatics.eml.EMLParser;
 
 
@@ -165,8 +167,9 @@
             	 dbconn = DBConnectionPool
                  .getDBConnection("EMLVersionsTransformer.handleSingleEML200Document");
                   serialNumber = dbconn.getCheckOutSerialNumber();
+                  String schemaLocation = XMLSchemaService.getInstance().getNameSpaceAndLocationStringWithoutFormatId();
                   documentWrapper.write(dbconn, eml210Content, pub, dtd,
-                          doAction, newId, owner, groups, null, formatId);
+                          doAction, newId, owner, groups, null, schemaLocation);
                   logMetacat.warn("Doc "+docidWithRev+" was transformed to eml210 with new id "+newId);
                   transformLog("Doc "+docidWithRev+" was transformed to eml210 with new id "+newId);
              }
