Index: src/edu/ucsb/nceas/metacat/MetaCatServlet.java
===================================================================
--- src/edu/ucsb/nceas/metacat/MetaCatServlet.java	(revision 2710)
+++ src/edu/ucsb/nceas/metacat/MetaCatServlet.java	(revision 2711)
@@ -157,6 +157,8 @@
 
     public static final String NONAMESPACELOCATION = ":noNamespaceSchemaLocation";
 
+    public static final String NAMESPACEKEYWORD = "xmlns";
+
     public static final String EML2KEYWORD = ":eml";
 
     public static final String XMLFORMAT = "xml";
@@ -1712,31 +1714,34 @@
                     // set a dtd base validation parser
                     String rule = DocumentImpl.DTD;
                     documentWrapper = new DocumentImplWrapper(rule, validate);
-                } else if (needSchemaValidation(xml)) {
-                    // for eml2
+                } else {
+
                     String namespace = findNamespace(xml);
-                    if (namespace.compareTo(DocumentImpl.EML2_0_0NAMESPACE) == 0
-                                || namespace.compareTo(
-                                DocumentImpl.EML2_0_1NAMESPACE) == 0) {
-                        // set eml2 base validation parser
-                        String rule = DocumentImpl.EML200;
-                        // using emlparser to check id validation
-                        EMLParser parser = new EMLParser(doctext[0]);
-                        documentWrapper = new DocumentImplWrapper(rule, true);
-                    } else if (namespace.compareTo(
+                    
+                	if (namespace != null) {
+                		if (namespace.compareTo(DocumentImpl.EML2_0_0NAMESPACE) == 0
+                				|| namespace.compareTo(
+                				DocumentImpl.EML2_0_1NAMESPACE) == 0) {
+                			// set eml2 base	 validation parser
+                			String rule = DocumentImpl.EML200;
+                			// using emlparser to check id validation
+                			EMLParser parser = new EMLParser(doctext[0]);
+                			documentWrapper = new DocumentImplWrapper(rule, true);
+                		} else if (namespace.compareTo(
                                 DocumentImpl.EML2_1_0NAMESPACE) == 0) {
-                        // set eml2 base validation parser
-                        String rule = DocumentImpl.EML210;
-                        // using emlparser to check id validation
-                        EMLParser parser = new EMLParser(doctext[0]);
-                        documentWrapper = new DocumentImplWrapper(rule, true);
-                    } else {
-                        // set schema base validation parser
-                        String rule = DocumentImpl.SCHEMA;
-                        documentWrapper = new DocumentImplWrapper(rule, true);
-                    }
-                } else {
-                    documentWrapper = new DocumentImplWrapper("", false);
+                			// set eml2 base validation parser
+                			String rule = DocumentImpl.EML210;
+                			// using emlparser to check id validation
+                			EMLParser parser = new EMLParser(doctext[0]);
+                			documentWrapper = new DocumentImplWrapper(rule, true);
+                		} else {
+                			// set schema base validation parser
+                			String rule = DocumentImpl.SCHEMA;
+                			documentWrapper = new DocumentImplWrapper(rule, true);
+                		}
+                	} else {
+                		documentWrapper = new DocumentImplWrapper("", false);
+                	}
                 }
 
                 String[] action = (String[]) params.get("action");
@@ -1868,32 +1873,6 @@
     // END OF INSERT/UPDATE SECTION
 
     /* check if the xml string contains key words to specify schema loocation */
-    private boolean needSchemaValidation(StringReader xml) throws IOException
-    {
-        boolean needSchemaValidate = false;
-        if (xml == null) {
-            logMetacat.warn("Validation for schema is "
-                    + needSchemaValidate);
-            return needSchemaValidate;
-        }
-        logMetacat.info("before get target line");
-        String targetLine = getSchemaLine(xml);
-        logMetacat.info("after get target line");
-        // to see if the second line contain some keywords
-        if (targetLine != null
-                && (targetLine.indexOf(SCHEMALOCATIONKEYWORD) != -1 || targetLine
-                        .indexOf(NONAMESPACELOCATION) != -1)) {
-            // if contains schema location key word, should be validate
-            needSchemaValidate = true;
-        }
-
-        logMetacat.warn("Validation for schema is "
-                + needSchemaValidate);
-        return needSchemaValidate;
-
-    }
-
-    /* check if the xml string contains key words to specify schema loocation */
     private String findNamespace(StringReader xml) throws IOException
     {
         String namespace = null;
@@ -1911,10 +1890,31 @@
 
         if (targetLine != null) {
 
-            int startIndex = targetLine.indexOf(SCHEMALOCATIONKEYWORD);
+        	// find if the root element has prefix
+        	String prefix = getPrefix(targetLine);
+        	int startIndex = 0;
+        	
+        	if(prefix != null)
+        	{
+        		// if prefix found then look for xmlns:prefix
+        		// element to find the ns 
+        		String namespaceWithPrefix = NAMESPACEKEYWORD + ":" + prefix;
+        		startIndex = targetLine.indexOf(namespaceWithPrefix);
+  
+        		// if xmlns:prefix not found, look 
+        		// for xmlns attribute to find the ns 
+        		if(startIndex == -1){
+            		startIndex = targetLine.indexOf(NAMESPACEKEYWORD);        			
+        		}
+        	} else {
+        		// if prefix not found then look for xmlns
+        		// attribute to find the ns 
+        		startIndex = targetLine.indexOf(NAMESPACEKEYWORD);
+        	}
+        		
             int start = 1;
             int end = 1;
-            String schemaLocation = null;
+            String namespaceString = null;
             int count = 0;
             if (startIndex != -1) {
                 for (int i = startIndex; i < targetLine.length(); i++) {
@@ -1929,16 +1929,22 @@
                         break;
                     }
                 }
+            } 
+            // else: xmlns not found. namespace = null will be returned
+
+            if(start < end){
+            	namespaceString = targetLine.substring(start + 1, end);
             }
-            schemaLocation = targetLine.substring(start + 1, end);
-            logMetacat.info("schemaLocation in xml is: "
-                    + schemaLocation);
-            if (schemaLocation.indexOf(eml2_0_0NameSpace) != -1) {
+            logMetacat.info("namespace in xml is: "
+                    + namespaceString);
+            if (namespaceString.indexOf(eml2_0_0NameSpace) != -1) {
                 namespace = eml2_0_0NameSpace;
-            } else if (schemaLocation.indexOf(eml2_0_1NameSpace) != -1) {
+            } else if (namespaceString.indexOf(eml2_0_1NameSpace) != -1) {
                 namespace = eml2_0_1NameSpace;
-            } else if (schemaLocation.indexOf(eml2_1_0NameSpace) != -1) {
+            } else if (namespaceString.indexOf(eml2_1_0NameSpace) != -1) {
                 namespace = eml2_1_0NameSpace;
+            } else {
+            	namespace = namespaceString;
             }
         }
 
@@ -2000,6 +2006,20 @@
         return secondLine;
     }
 
+    private String getPrefix(String schemaLine)
+    {
+    	String prefix = null;
+    	String rootElement = schemaLine.substring(0, schemaLine.indexOf(" "));
+        logMetacat.warn("rootElement:" + rootElement);
+        
+        if(rootElement.indexOf(":") > 0){
+        	prefix = rootElement.substring(rootElement.indexOf(":") + 1,
+        			rootElement.length());
+        } 
+        logMetacat.warn("prefix:" + prefix);        
+        return prefix;
+    }
+
     /**
      * Handle the database delete request and delete an XML document from the
      * database connection
