Index: src/edu/ucsb/nceas/metacat/DBSAXHandler.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DBSAXHandler.java	(revision 1410)
+++ src/edu/ucsb/nceas/metacat/DBSAXHandler.java	(revision 1411)
@@ -71,6 +71,11 @@
    private boolean endDocument = false;
    protected int serverCode = 1;
    protected Hashtable namespaces = new Hashtable();
+   protected boolean hitTextNode = false; // a flag to hit text node
+   // a buffer to keep all text nodes for same element
+   // it is for element was splited
+   protected StringBuffer textBuffer = new StringBuffer();
+   protected Stack textBufferStack = new Stack();
 
    protected static final int MAXDATACHARS = 4000;
    protected static final long INDEXDELAY = 10000;
@@ -194,7 +199,6 @@
      MetaCatUtil.debugMessage("Start ELEMENT(localName) " + localName, 50);
      MetaCatUtil.debugMessage("Start ELEMENT(uri) " + uri, 50);
      
-     
      DBSAXNode parentNode = null;
      DBSAXNode currentNode = null;
 
@@ -204,6 +208,20 @@
      } catch (EmptyStackException e) {
        parentNode = null;
      }
+     
+     // If hit a text node, we need write this text for current's parent node
+     // This will happend if the element is mixted
+     if (hitTextNode && parentNode != null)
+     {
+       // write the textbuffer into db for parent node.
+        writeTextForDBSAXNode(textBuffer, parentNode);
+        // rest hitTextNode
+        hitTextNode =false;
+        // reset textbuffer
+        textBuffer = null;
+        textBuffer = new StringBuffer();
+       
+     }
 
      // Document representation that points to the root document node
      if (atFirstElement) 
@@ -449,34 +467,16 @@
 
 
   /** SAX Handler that is called for each XML text node */
-  public void characters(char[] cbuf, int start, int len) throws SAXException {
+  public void characters(char[] cbuf, int start, int len) throws SAXException 
+  {
      MetaCatUtil.debugMessage("CHARACTERS", 50);
-     DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
-     String data = null;
-     int leftover = len;
-     int offset = start;
-     boolean moredata = true;
+     // buffer all text nodes for same element. This is for text was splited
+     // into different nodes
+     textBuffer.append(new String(cbuf, start,len));
+     // set hittextnode true
+     hitTextNode = true;
+  }
 
-     // This loop deals with the case where there are more characters
-     // than can fit in a single database text field (limit is
-     // MAXDATACHARS).  If the text to be inserted exceeds MAXDATACHARS,
-     // write a series of nodes that are MAXDATACHARS long, and then the
-     // final node contains the remainder
-     while (moredata) {
-       if (leftover > MAXDATACHARS) {
-         data = new String(cbuf, offset, MAXDATACHARS);
-         leftover -= MAXDATACHARS;
-         offset += MAXDATACHARS;
-       } else {
-         data = new String(cbuf, offset, leftover);
-         moredata = false;
-       }
-
-       // Write the content of the node to the database
-       currentNode.writeChildNodeToDB("TEXT", null, data, docid);
-     }
-   }
-
    /**
     * SAX Handler that is called for each XML text node that is
     * Ignorable white space
@@ -530,9 +530,27 @@
    public void endElement(String uri, String localName,
                           String qName) throws SAXException {
      MetaCatUtil.debugMessage("End ELEMENT " + qName, 50);
+     
+     // write buffered text nodes into db (so no splited)
+     DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
+      
+     // If before the end element, the parser hit text nodes and store them
+     // into the buffer, write the buffer to data base. The reason we put
+     // write database here is for xerces some time split text node
+     if (hitTextNode)
+     {
+       MetaCatUtil.debugMessage("Write text into DB in End Element", 50);
+       writeTextForDBSAXNode(textBuffer, currentNode);
+     }//if
+     
+     //set hitText false
+     hitTextNode = false;
+     // reset textbuff
+     textBuffer = null;
+     textBuffer = new StringBuffer();
 
      // Get the node from the stack
-     DBSAXNode currentNode = (DBSAXNode)nodeStack.pop();
+     currentNode = (DBSAXNode)nodeStack.pop();
    }
 
    //
@@ -705,4 +723,48 @@
    public boolean processingDTD() {
      return processingDTD;
    }
+   
+   /* Method to write a text buffer for DBSAXNode*/
+   protected void writeTextForDBSAXNode(StringBuffer strBuffer, DBSAXNode node)
+                                      throws SAXException
+   {
+     // Check parameter
+     if ( strBuffer == null || node == null)
+     {
+       return;
+     }
+     boolean moredata = true;
+     String data = null;
+     int bufferSize = strBuffer.length();
+     int start = 0;
+    
+     // if there are some cotent in buffer, write it
+     if (bufferSize > 0)
+     {
+       MetaCatUtil.debugMessage("Write text into DB", 50);
+       // This loop deals with the case where there are more characters
+       // than can fit in a single database text field (limit is
+       // MAXDATACHARS).  If the text to be inserted exceeds MAXDATACHARS,
+       // write a series of nodes that are MAXDATACHARS long, and then the
+       // final node contains the remainder
+       while (moredata) 
+       {
+          bufferSize = strBuffer.length();
+          if (bufferSize > MAXDATACHARS) 
+         {
+            data = strBuffer.substring(start, MAXDATACHARS);
+            // cut the stringbuffer part that already written into db
+            strBuffer = strBuffer.delete(start, MAXDATACHARS);
+          } 
+          else 
+          {
+            data = strBuffer.substring(start, bufferSize);
+            moredata = false;
+          }
+       
+          // Write the content of the node to the database
+          node.writeChildNodeToDB("TEXT", null, data, docid);
+        }//while
+     }//if
+   }
 }
