Index: src/edu/ucsb/nceas/metacat/DBSAXHandler.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DBSAXHandler.java	(revision 109)
+++ src/edu/ucsb/nceas/metacat/DBSAXHandler.java	(revision 110)
@@ -62,6 +62,11 @@
    public void startDocument() throws SAXException
    {
     System.out.println("start Document");
+    // Create the document node represantation as root
+    DBSAXElement documentNode = new DBSAXElement(conn, docname, 0, 0);
+    // Add the element to the stack, so that any text data can be 
+    // added as it is encountered
+    elementStack.push(documentNode);
    }
 
    /** SAX Handler that receives notification of end of the document */
@@ -80,12 +85,6 @@
     System.out.println("DOCNAME: " + docname);
     System.out.println("DOCTYPE: " + doctype);
     System.out.println("  SYSID: " + systemid);
-
-    // Create the document node represantation as root
-    DBSAXElement documentNode = new DBSAXElement(conn, docname, 0, 0);
-    // Add the element to the stack, so that any text data can be 
-    // added as it is encountered
-    elementStack.push(documentNode);
    }
 
    /** SAX Handler that receives notification of end of DTD 
@@ -95,10 +94,6 @@
    public void endDoctype() throws SAXException
    {
     System.out.println("end of DOCTYPE");
-    //if (doctype == null)
-    //    doctype = DBEntityResolver.doctype;
-    //DBSAXElement documentNode = (DBSAXElement)elementStack.peek();
-    //new DBSAXDocument(conn, documentNode.getElementID(), docname, doctype);
    }
 
    /** SAX Handler that is called at the start of each XML element */
@@ -142,16 +137,11 @@
         else if (doctype == null)
             doctype = DBEntityResolver.doctype;
         DBSAXElement documentNode = (DBSAXElement)elementStack.peek();
+        documentNode.writeNodename(docname);
         new DBSAXDocument(conn, documentNode.getElementID(), docname, doctype);
       }      
       // Create the current element representation
       currentElement = new DBSAXElement(conn, localName, parent_id, nodeIndex);
-      // go to create document definition in the db
-      // call once after insertion of the first element
-      if (parent_id == 0) {
-        long rootnodeid = currentElement.getElementID();
-        new DBSAXDocument(conn, rootnodeid, docname, doctype);
-      }
 
       // Add all of the attributes
       for (int i=0; i<atts.getLength(); i++)
Index: src/edu/ucsb/nceas/metacat/DBSAXNode.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DBSAXNode.java	(revision 109)
+++ src/edu/ucsb/nceas/metacat/DBSAXNode.java	(revision 110)
@@ -84,7 +84,6 @@
           // Bind the values to the query
           pstmt.setString(1, "COMMENT");
           pstmt.setLong(2, getElementID());
-          //System.out.println(data.length());
           pstmt.setString(3, data);
           pstmt.setInt(4, nodeIndex);
           // Do the insertion
@@ -117,6 +116,25 @@
         }
     }
 
+    /** creates SQL code to put nodename for the document node into DB connection */
+    void writeNodename(String nodename) {
+        try {
+          PreparedStatement pstmt;
+          pstmt = conn.prepareStatement(
+                "UPDATE xml_nodes set nodename = ? " +
+                "WHERE nodeid = ?");
+
+          // Bind the values to the query
+          pstmt.setString(1, nodename);
+          pstmt.setLong(2, getElementID());
+          // Do the insertion
+          pstmt.execute();
+          pstmt.close();
+        } catch (SQLException e) {
+          System.out.println(e.getMessage());
+        }
+    }
+
     /** look up the assigned element id from DB connection */
     private long getAssignedElementID() {
         long assigned_id=0;
Index: src/edu/ucsb/nceas/metacat/DBSAXElement.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DBSAXElement.java	(revision 109)
+++ src/edu/ucsb/nceas/metacat/DBSAXElement.java	(revision 110)
@@ -84,7 +84,6 @@
           // Bind the values to the query
           pstmt.setString(1, "COMMENT");
           pstmt.setLong(2, getElementID());
-          //System.out.println(data.length());
           pstmt.setString(3, data);
           pstmt.setInt(4, nodeIndex);
           // Do the insertion
@@ -117,6 +116,25 @@
         }
     }
 
+    /** creates SQL code to put nodename for the document node into DB connection */
+    void writeNodename(String nodename) {
+        try {
+          PreparedStatement pstmt;
+          pstmt = conn.prepareStatement(
+                "UPDATE xml_nodes set nodename = ? " +
+                "WHERE nodeid = ?");
+
+          // Bind the values to the query
+          pstmt.setString(1, nodename);
+          pstmt.setLong(2, getElementID());
+          // Do the insertion
+          pstmt.execute();
+          pstmt.close();
+        } catch (SQLException e) {
+          System.out.println(e.getMessage());
+        }
+    }
+
     /** look up the assigned element id from DB connection */
     private long getAssignedElementID() {
         long assigned_id=0;
Index: src/edu/ucsb/nceas/metacat/DBWriter.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DBWriter.java	(revision 109)
+++ src/edu/ucsb/nceas/metacat/DBWriter.java	(revision 110)
@@ -124,7 +124,6 @@
      } catch (SAXException e) {
        System.err.println(e.getMessage());
      } catch (Exception e) {
-       System.err.println("here is the URL exception");
        System.err.println(e.toString());
      }
   }
Index: src/edu/ucsb/nceas/metacat/DBSAXWriter.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DBSAXWriter.java	(revision 109)
+++ src/edu/ucsb/nceas/metacat/DBSAXWriter.java	(revision 110)
@@ -124,7 +124,6 @@
      } catch (SAXException e) {
        System.err.println(e.getMessage());
      } catch (Exception e) {
-       System.err.println("here is the URL exception");
        System.err.println(e.toString());
      }
   }
Index: DBSAXElement.java
===================================================================
--- DBSAXElement.java	(revision 109)
+++ DBSAXElement.java	(revision 110)
@@ -84,7 +84,6 @@
           // Bind the values to the query
           pstmt.setString(1, "COMMENT");
           pstmt.setLong(2, getElementID());
-          //System.out.println(data.length());
           pstmt.setString(3, data);
           pstmt.setInt(4, nodeIndex);
           // Do the insertion
@@ -117,6 +116,25 @@
         }
     }
 
+    /** creates SQL code to put nodename for the document node into DB connection */
+    void writeNodename(String nodename) {
+        try {
+          PreparedStatement pstmt;
+          pstmt = conn.prepareStatement(
+                "UPDATE xml_nodes set nodename = ? " +
+                "WHERE nodeid = ?");
+
+          // Bind the values to the query
+          pstmt.setString(1, nodename);
+          pstmt.setLong(2, getElementID());
+          // Do the insertion
+          pstmt.execute();
+          pstmt.close();
+        } catch (SQLException e) {
+          System.out.println(e.getMessage());
+        }
+    }
+
     /** look up the assigned element id from DB connection */
     private long getAssignedElementID() {
         long assigned_id=0;
Index: DBSAXWriter.java
===================================================================
--- DBSAXWriter.java	(revision 109)
+++ DBSAXWriter.java	(revision 110)
@@ -124,7 +124,6 @@
      } catch (SAXException e) {
        System.err.println(e.getMessage());
      } catch (Exception e) {
-       System.err.println("here is the URL exception");
        System.err.println(e.toString());
      }
   }
Index: DBSAXHandler.java
===================================================================
--- DBSAXHandler.java	(revision 109)
+++ DBSAXHandler.java	(revision 110)
@@ -62,6 +62,11 @@
    public void startDocument() throws SAXException
    {
     System.out.println("start Document");
+    // Create the document node represantation as root
+    DBSAXElement documentNode = new DBSAXElement(conn, docname, 0, 0);
+    // Add the element to the stack, so that any text data can be 
+    // added as it is encountered
+    elementStack.push(documentNode);
    }
 
    /** SAX Handler that receives notification of end of the document */
@@ -80,12 +85,6 @@
     System.out.println("DOCNAME: " + docname);
     System.out.println("DOCTYPE: " + doctype);
     System.out.println("  SYSID: " + systemid);
-
-    // Create the document node represantation as root
-    DBSAXElement documentNode = new DBSAXElement(conn, docname, 0, 0);
-    // Add the element to the stack, so that any text data can be 
-    // added as it is encountered
-    elementStack.push(documentNode);
    }
 
    /** SAX Handler that receives notification of end of DTD 
@@ -95,10 +94,6 @@
    public void endDoctype() throws SAXException
    {
     System.out.println("end of DOCTYPE");
-    //if (doctype == null)
-    //    doctype = DBEntityResolver.doctype;
-    //DBSAXElement documentNode = (DBSAXElement)elementStack.peek();
-    //new DBSAXDocument(conn, documentNode.getElementID(), docname, doctype);
    }
 
    /** SAX Handler that is called at the start of each XML element */
@@ -142,16 +137,11 @@
         else if (doctype == null)
             doctype = DBEntityResolver.doctype;
         DBSAXElement documentNode = (DBSAXElement)elementStack.peek();
+        documentNode.writeNodename(docname);
         new DBSAXDocument(conn, documentNode.getElementID(), docname, doctype);
       }      
       // Create the current element representation
       currentElement = new DBSAXElement(conn, localName, parent_id, nodeIndex);
-      // go to create document definition in the db
-      // call once after insertion of the first element
-      if (parent_id == 0) {
-        long rootnodeid = currentElement.getElementID();
-        new DBSAXDocument(conn, rootnodeid, docname, doctype);
-      }
 
       // Add all of the attributes
       for (int i=0; i<atts.getLength(); i++)
