def get_text(elem): res = u'' for line in elem.childNodes: res += line.nodeValue return res.encode('utf-8') def Keywords(self, sessID, queryID): """ parse incoming query, queryLanguage == keywords """ sess = self._getSession(sessID) query = sess.getQuery(queryID) query = query.strip() user = sess.username res = {} res['getAuthor'] = user res['fulltext'] = query return res def VSQI(self, sessID, queryID): """ parse incoming query, queryLanguage == VSQI """ sess = self._getSession(sessID) query = sess.getQuery(queryID) query = query.strip() from xml.dom.minidom import parseString q = parseString(query) q.normalize() keywords = '' obj_uid = None elem_k = q.getElementsByTagName('keyword') for x in elem_k: keywords += ' '+get_text(x) obj = q.getElementsByTagName('object_uid') # there should be only one for x in obj: obj_uid = get_text(x) user = sess.username res = {} res['getAuthor'] = user res['fulltext'] = keywords if obj_uid: res['object_uid'] = obj_uid return res