Index: src/edu/ucsb/nceas/metacat/QuerySpecification.java
===================================================================
--- src/edu/ucsb/nceas/metacat/QuerySpecification.java	(revision 2375)
+++ src/edu/ucsb/nceas/metacat/QuerySpecification.java	(revision 2376)
@@ -908,10 +908,9 @@
             Hashtable unaccessableNodePair)
     {
         StringBuffer self = new StringBuffer();
-        self.append("select xml_nodes.docid, xml_index.path, xml_nodes.nodedata, ");
-        self.append("xml_nodes.parentnodeid ");
-        self.append("from xml_index, xml_nodes where xml_index.nodeid=");
-        self.append("xml_nodes.parentnodeid and (xml_index.path like '");
+        self.append("select path, docid, nodedata, ");
+        self.append("nodeid ");
+        self.append("from xml_index where (path like '");
         boolean firstfield = true;
         //put the returnfields into the query
         //the for loop allows for multiple fields
@@ -921,14 +920,15 @@
                 self.append((String) returnFieldList.elementAt(i));
                 self.append("' ");
             } else {
-                self.append("or xml_index.path like '");
+                self.append("or path like '");
                 self.append((String) returnFieldList.elementAt(i));
                 self.append("' ");
             }
         }
-        self.append(") AND xml_nodes.docid in (");
+        self.append(") AND docid in (");
         self.append(doclist);
-        self.append(") AND xml_nodes.nodetype = 'TEXT'");
+        self.append(")");
+        //self.append(") AND xml_nodes.nodetype = 'TEXT'");
 
         addAccessRestrictionSQL(unaccessableNodePair, self);
 
Index: src/edu/ucsb/nceas/metacat/DocumentImpl.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DocumentImpl.java	(revision 2375)
+++ src/edu/ucsb/nceas/metacat/DocumentImpl.java	(revision 2376)
@@ -1180,6 +1180,15 @@
             nodeRecordMap.put(nodeId, currentNode);
         }
 
+        // Build a map of the node records that can be accessed by nodeId
+        HashMap parentNodeRecordMap = new HashMap();
+        Iterator ite = nodeRecordLists.iterator();
+        while (ite.hasNext()) {
+            NodeRecord currentNode = (NodeRecord) ite.next();
+            Long nodeId = new Long(currentNode.getParentNodeId());
+            parentNodeRecordMap.put(nodeId, currentNode);
+        }
+
         // Opening separate db connection for deleting and writing
         // XML Index -- be sure that it is all in one db transaction
         int serialNumber = -1;
@@ -1204,6 +1213,19 @@
                 if (currentNode.nodetype.equals("ELEMENT") ||
                     currentNode.nodetype.equals("ATTRIBUTE") ) {
 
+                    String nodedata = null;
+
+                    if (currentNode.nodetype.equals("ELEMENT") ) {
+                        Long nodeid = new Long(currentNode.getNodeId());
+                        NodeRecord node =
+                            (NodeRecord) parentNodeRecordMap.get(nodeid);
+                        if(node!=null){
+                            nodedata = node.getNodeData();
+                        }
+                    } else {
+                        nodedata = currentNode.getNodeData();
+                    }
+
                     if (atRootElement) {
                         rootNodeId = currentNode.getNodeId();
                         atRootElement = false;
@@ -1210,7 +1232,7 @@
                     }
                     traverseParents(nodeRecordMap, rootNodeId,
                             currentNode.getNodeId(),
-                            currentNode.getNodeId(), "", pathList);
+                            currentNode.getNodeId(), "", pathList, nodedata);
                     updateNodeIndex(dbConn, pathList);
                 }
             }
@@ -1243,10 +1265,11 @@
      * @param id the id of the current node to be processed
      * @param children the string representation of all child nodes of this id
      * @param pathList the hash to which paths are added
+     * @param nodedata the nodedata for the current node
      */
     private void traverseParents(HashMap records, long rootNodeId,
             long leafNodeId, long id,
-            String children, HashMap pathList) {
+            String children, HashMap pathList, String nodedata) {
         Long nodeId = new Long(id);
         NodeRecord current = (NodeRecord)records.get(nodeId);
         long parentId = current.getParentNodeId();
@@ -1259,26 +1282,26 @@
                     currentName = "@" + currentName;
                 }
                 MetaCatUtil.debugMessage("A: " + currentName +"\n", 60);
-                pathList.put(currentName, new PathIndexEntry(
-                    leafNodeId, currentName, docid, doctype, parentId));
+                pathList.put(currentName, new PathIndexEntry(leafNodeId,
+                    currentName, docid, doctype, parentId, nodedata));
             }
             currentName = "/" + currentName;
             currentName = currentName + children;
             if (parentId != 0) {
                 traverseParents(records, rootNodeId, leafNodeId,
-                    parentId, currentName, pathList);
+                    parentId, currentName, pathList, nodedata);
             }
             String path = current.getNodeName() + children;
             if (!children.equals("")) {
                 MetaCatUtil.debugMessage("B: " + path +"\n", 60);
                 pathList.put(path, new PathIndexEntry(leafNodeId, path, docid,
-                    doctype, parentId));
+                    doctype, parentId, nodedata));
             }
             if (id == rootNodeId) {
                 String fullPath = '/' + path;
                 MetaCatUtil.debugMessage("C: " + fullPath +"\n", 60);
                 pathList.put(fullPath, new PathIndexEntry(leafNodeId, fullPath,
-                    docid, doctype, parentId));
+                    docid, doctype, parentId, nodedata));
             }
         }
     }
@@ -1325,7 +1348,7 @@
         // insertions
         PreparedStatement pstmt = conn.prepareStatement(
                 "INSERT INTO xml_index (nodeid, path, docid, doctype, " +
-                "parentnodeid) " + "VALUES (?, ?, ?, ?, ?)");
+                "parentnodeid, nodedata) " + "VALUES (?, ?, ?, ?, ?, ?)");
         // Increase usage count for the connection
         conn.increaseUsageCount(1);
         String familyId = MetaCatUtil.getDocIdFromString(docid);
@@ -1341,6 +1364,7 @@
             pstmt.setLong(1, entry.nodeId);
             pstmt.setString(2, entry.path);
             pstmt.setLong(5, entry.parentId);
+            pstmt.setString(6, entry.nodedata);
             pstmt.executeUpdate();
         }
         // Close the database statement
Index: src/edu/ucsb/nceas/metacat/DBQuery.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DBQuery.java	(revision 2375)
+++ src/edu/ucsb/nceas/metacat/DBQuery.java	(revision 2376)
@@ -719,7 +719,10 @@
                fielddata = MetaCatUtil.normalize(fielddata);
                String parentId = rs.getString(4);
                StringBuffer value = new StringBuffer();
-               if (!containsKey(parentidList, parentId))
+
+	       // if xml_index is used, there would be just one record per nodeid
+	       // as xml_index just keeps one entry for each path
+               if (useXMLIndex || !containsKey(parentidList, parentId))
                {
                   // don't need to merger nodedata
                   value.append("<param name=\"");
Index: src/edu/ucsb/nceas/metacat/PathIndexEntry.java
===================================================================
--- src/edu/ucsb/nceas/metacat/PathIndexEntry.java	(revision 2375)
+++ src/edu/ucsb/nceas/metacat/PathIndexEntry.java	(revision 2376)
@@ -27,7 +27,7 @@
 /**
  * PathIndexEntry contains all of the data fields needed to insert an path into
  * the xml_index table.
- * 
+ *
  * @author jones
  */
 public class PathIndexEntry
@@ -34,13 +34,14 @@
 {
     protected long nodeId;
     protected String path;
-    protected String docid; 
+    protected String docid;
     protected String docType;
     protected long parentId;
-    
+    protected String nodedata;
+
     /**
      * Construct a new PathIndexEntry.
-     * 
+     *
      * @param nodeId the node identifier
      * @param path the path in the xml document
      * @param docid the document identifier
@@ -47,8 +48,8 @@
      * @param docType the document type
      * @param parentId the identifier of the parent node
      */
-    public PathIndexEntry(long nodeId, String path, String docid, 
-            String docType, long parentId)
+    public PathIndexEntry(long nodeId, String path, String docid,
+            String docType, long parentId, String nodedata)
     {
         this.nodeId = nodeId;
         this.path = path;
@@ -55,5 +56,6 @@
         this.docid = docid;
         this.docType = docType;
         this.parentId = parentId;
+        this.nodedata = nodedata;
     }
 }
