Index: ne_props.c
===================================================================
--- ne_props.c	(revision 698)
+++ ne_props.c	(revision 959)
@@ -37,7 +37,12 @@
 
 /* don't store flat props with a value > 10K */
 #define MAX_FLATPROP_LEN (102400)
-
+struct prop_namespace {
+    const char *nspace;
+    char *prefix;
+    int depth;
+    struct prop_namespace* next;
+};
 struct ne_propfind_handler_s {
     ne_session *sess;
     ne_request *request;
@@ -59,7 +64,7 @@
 
     ne_buffer *value; /* current flat property value */
     int depth; /* nesting depth within a flat property */
-
+    struct prop_namespace ns; /* namespace declared in the current scope */
     ne_props_result callback;
     void *userdata;
 };
@@ -382,7 +387,28 @@
     /* And return this as the new pstat. */
     return &set->pstats[n];
 }
+static void findns(const char *nspace, ne_propfind_handler *hdl, const char **pre, const char **nsuri)
+{
+    struct prop_namespace* ns=&hdl->ns;
+    struct prop_namespace* last=NULL;
 
+    while (ns && strcmp(ns->nspace,nspace)!=0) {
+        last = ns;
+        ns=ns->next;
+    }
+    if (!ns) {
+        char prefix[8];
+        ne_snprintf(prefix,8,"ns%i",hdl->depth);
+        ns = ne_calloc(sizeof(struct prop_namespace));
+        ns->depth= hdl->depth;
+        ns->nspace=nspace;
+        ns->prefix=ne_strdup(prefix);
+        *nsuri=nspace;
+        last->next = ns;
+    } 
+    *pre = ns->prefix;
+}
+
 static int startelm(void *userdata, int parent,
                     const char *nspace, const char *name, const char **atts)
 {
@@ -399,9 +425,30 @@
 
     if (parent == ELM_flatprop) {
         /* collecting the flatprop value. */
+        const char* pre=NULL;
+        const char* nsuri=NULL;
         hdl->depth++;
-        if (hdl->value->used < MAX_FLATPROP_LEN)
-            ne_buffer_concat(hdl->value, "<", name, ">", NULL);
+        // namespace handeling
+        if (nspace) {
+            findns(nspace, hdl, &pre, &nsuri);
+        }
+        if (hdl->value->used < MAX_FLATPROP_LEN) {
+            const char **attlist=atts;
+            
+            if (pre)
+                ne_buffer_concat(hdl->value, "<", pre, ":", name, NULL);
+            else
+                ne_buffer_concat(hdl->value, "<", name, NULL);
+            // also add the attributes
+            while (*attlist){
+                ne_buffer_concat(hdl->value, " ", attlist[0], "=\"", attlist[1], "\"", NULL);
+                attlist+=2;
+            }
+            if (nsuri)
+                ne_buffer_concat(hdl->value, " xmlns:", pre, "=\"", nsuri, "\">", NULL);
+            else
+                ne_buffer_concat(hdl->value, ">", NULL);
+        }
         return ELM_flatprop;
     }        
 
@@ -446,7 +493,11 @@
     }
 
     hdl->depth = 0;
-
+    hdl->ns.depth= 0;
+    hdl->ns.nspace=nspace;
+    hdl->ns.prefix=NULL;
+    hdl->ns.next=NULL;
+    
     return ELM_flatprop;
 }
 
@@ -456,18 +507,49 @@
     ne_propfind_handler *hdl = userdata;
     struct propstat *pstat = ne_207_get_current_propstat(hdl->parser207);
     int n;
+    struct prop_namespace* ns=&hdl->ns;
+    struct prop_namespace* next=NULL;
+    struct prop_namespace* cur=NULL;
 
     if (hdl->depth > 0) {
         /* nested. */
-        if (hdl->value->used < MAX_FLATPROP_LEN)
-            ne_buffer_concat(hdl->value, "</", name, ">", NULL);
+        const char* pre=NULL;
+        const char* nsuri=NULL;
+        if (nspace) {
+            findns(nspace, hdl, &pre, &nsuri);
+        }
+        if (hdl->value->used < MAX_FLATPROP_LEN){
+            if (pre)
+                ne_buffer_concat(hdl->value, "</", pre, ":", name, ">", NULL);
+            else
+                ne_buffer_concat(hdl->value, "</", name, ">", NULL);
+        }
         hdl->depth--;
     } else {
         /* end of the current property value */
+        
+        
         n = pstat->numprops - 1;
         pstat->props[n].value = ne_buffer_finish(hdl->value);
         hdl->value = ne_buffer_create();
     }
+    // remove non longer valid namespace
+    while (ns){
+        if (ns->depth>hdl->depth){
+            // delete all namespace from this point
+            while (ns) {
+                next = ns->next;
+                if (ns->prefix)
+                    ne_free(ns->prefix);
+                ne_free(ns);
+                ns = next;
+            }
+            cur->next = NULL;
+        } else {
+            cur = ns;
+            ns = ns ->next;
+        }
+    }
     return 0;
 }
 
