diff --git a/modules_k/xcap_server/xcap_misc.c b/modules_k/xcap_server/xcap_misc.c
index 146e941..7a0520c 100644
--- a/modules_k/xcap_server/xcap_misc.c
+++ b/modules_k/xcap_server/xcap_misc.c
@@ -295,13 +295,7 @@ int xcaps_xpath_get(str *inbuf, str *xpaths, str *outbuf)
 	xmlXPathContextPtr xpathCtx = NULL; 
 	xmlXPathObjectPtr xpathObj = NULL; 
 	xmlNodeSetPtr nodes;
-	xmlChar *keyword;
 	xmlBufferPtr psBuf;
-	int size;
-	int i;
-	char *p;
-	char *end;
-	char *pos;
 
 	doc = xmlParseMemory(inbuf->s, inbuf->len);
 	if(doc == NULL)
@@ -330,72 +324,37 @@ int xcaps_xpath_get(str *inbuf, str *xpaths, str *outbuf)
 		outbuf->s[outbuf->len] = '\0';
 		goto done;
 	}
-	size = nodes->nodeNr;
-    p = outbuf->s;
-	end = outbuf->s + outbuf->len;
-	for(i = 0; i < size; ++i)
+	
+	
+	psBuf = xmlBufferCreate();
+	if(psBuf != NULL && xmlNodeDump(psBuf, doc,
+									nodes->nodeTab[0], 0, 0)>0)
 	{
-		if(nodes->nodeTab[i]==NULL)
-			continue;
-		if(i!=0)
-		{
-			if(p>=end)
-			{
-				LM_ERR("output buffer overflow\n");
-				goto error;
-			}
-			*p = ',';
-			p++;
+		outbuf->len = strlen((char*)xmlBufferContent(psBuf));
+		
+		if (outbuf->len == 0) {
+			outbuf->len = 1;
+			outbuf->s[outbuf->len] = '\0';
+			
+			goto done;
 		}
-		if(nodes->nodeTab[i]->type == XML_ATTRIBUTE_NODE)
+		
+		outbuf->s = (char*)pkg_malloc(outbuf->len);
+		
+		if(outbuf->s==NULL)
 		{
-			keyword = xmlNodeListGetString(doc,
-				nodes->nodeTab[i]->children, 0);
-			if(keyword != NULL)
-			{
-				pos = p + strlen((char*)keyword);
-				if(pos>=end)
-				{
-					LM_ERR("output buffer overflow\n");
-					goto error;
-				}
-				strcpy(p, (char*)keyword);
-				p = pos;
-				xmlFree(keyword);
-				keyword = NULL;
-			}
-		} else {
-			if(nodes->nodeTab[i]->content!=NULL)
-			{
-				pos = p + strlen((char*)nodes->nodeTab[i]->content);
-				if(pos>=end)
-				{
-					LM_ERR("output buffer overflow\n");
-					goto error;
-				}
-				strcpy(p, (char*)nodes->nodeTab[i]->content);
-				p = pos;
-			} else {
-				psBuf = xmlBufferCreate();
-				if(psBuf != NULL && xmlNodeDump(psBuf, doc,
-						nodes->nodeTab[i], 0, 0)>0)
-				{
-					pos = p + strlen((char*)xmlBufferContent(psBuf));
-					if(pos>=end)
-					{
-						LM_ERR("output buffer overflow\n");
-						goto error;
-					}
-					strcpy(p, (char*)xmlBufferContent(psBuf));
-					p = pos;
-				}
-				if(psBuf != NULL) xmlBufferFree(psBuf);
-				psBuf = NULL;
-			}
+			outbuf->len = 1;
+			outbuf->s[outbuf->len] = '\0';
+			
+			goto done;
 		}
+		
+		strcpy(outbuf->s, (char*)xmlBufferContent(psBuf));
+		
+		goto done;
 	}
-	outbuf->len = p - outbuf->s;
-	outbuf->s[outbuf->len] = '\0';
+	
+	goto done;
 
 done:
 	if(xpathObj!=NULL) xmlXPathFreeObject(xpathObj);
diff --git a/modules_k/xcap_server/xcap_server.c b/modules_k/xcap_server/xcap_server.c
index 7b44585..dfab5b1 100644
--- a/modules_k/xcap_server/xcap_server.c
+++ b/modules_k/xcap_server/xcap_server.c
@@ -858,7 +858,8 @@ static int w_xcaps_get(sip_msg_t* msg, char* puri, char* ppath)
 	str uri;
 	str path;
 	str etag;
-	str body;
+	str xmldoc;
+	str body = {0, 0};
 	int ret = 0;
 	xcap_uri_t xuri;
 	str *ctype;
@@ -928,11 +929,39 @@ static int w_xcaps_get(sip_msg_t* msg, char* puri, char* ppath)
 		return -2;
 	}
 
-	if((ret=xcaps_get_db_doc(&turi.user, &turi.host, &xuri, &body))<0)
+	if((ret=xcaps_get_db_doc(&turi.user, &turi.host, &xuri, &xmldoc))<0)
 	{
 		LM_ERR("could not fetch xcap document\n");
 		goto error;
 	}
+	
+	if (xuri.node.s != NULL) 
+	{
+		body.len = 1;
+		body.s = (char*)pkg_malloc(body.len);
+		body.s[body.len] = '\0';
+		
+		if(xcaps_xpath_hack(&xmldoc, 0)<0)
+		{
+			LM_ERR("could not hack xcap document\n");
+			goto error;
+		}
+		if(xcaps_xpath_get(&xmldoc, &xuri.node, &body)<0)
+		{
+			LM_ERR("could not filter xcap document\n");
+			goto error;
+		}
+		
+		if(xcaps_xpath_hack(&body, 1)<0)
+		{
+			LM_ERR("could not hack xcap document\n");
+			goto error;
+		}
+	}
+	else {
+		body = xmldoc;
+	}
+	
 	if(ret==0)
 	{
 		/* doc found */
