Index: dwriter.c
===================================================================
--- dwriter.c	(revision 2231)
+++ dwriter.c	(working copy)
@@ -28,73 +28,107 @@
 #define CS  (w->state[w->depth])
 #define OUT (w->buf)
 
-#define ADD_SEP                                                         \
-        do {							      	\
-	        if ((CS == dwriter_dict_key) ||				\
-		    (CS == dwriter_list_in))				\
-		{							\
-			cherokee_buffer_add_str (OUT, ",");		\
-			if (w->pretty)					\
-				cherokee_buffer_add_str(OUT, "\n");	\
-		} else if (CS == dwriter_dict_val) {			\
-			if ((w->lang == dwriter_php) ||			\
-			    (w->lang == dwriter_ruby))			\
-				cherokee_buffer_add_str (OUT, "=>");	\
-			else						\
-				cherokee_buffer_add_str (OUT, ":");	\
-			if (w->pretty)					\
-				cherokee_buffer_add_str (OUT, " ");	\
-		}							\
-	} while(0)
+#define ADD_SEP                                                                 \
+        do {                                                                    \
+            if (w->lang == dwriter_xmlrpc) {                                    \
+                if (CS == dwriter_dict_key) {                                   \
+                     if (w->pretty)                                             \
+                        cherokee_buffer_add_str (OUT, "\t");                    \
+                     cherokee_buffer_add_str (OUT, "<member>");                 \
+                     if (w->pretty)                                             \
+                        cherokee_buffer_add_str (OUT, "\n\t");                  \
+                     cherokee_buffer_add_str (OUT, "<name>");                   \
+                } else if (CS == dwriter_list_in || CS == dwriter_dict_val) {   \
+                    if (w->pretty)                                              \
+                        cherokee_buffer_add_str (OUT, "\t\t");                  \
+                     cherokee_buffer_add_str (OUT, "<value>");                  \
+                }                                                               \
+            } else {                                                            \
+	            if ((CS == dwriter_dict_key) ||				                    \
+        		    (CS == dwriter_list_in)) {                                  \
+			            cherokee_buffer_add_str (OUT, ",");		                \
+            			if (w->pretty)					                        \
+			            	cherokee_buffer_add_str(OUT, "\n");	                \
+        		} else if (CS == dwriter_dict_val) {			                \
+        			if ((w->lang == dwriter_php) ||			                    \
+		        	    (w->lang == dwriter_ruby))			                    \
+			        	cherokee_buffer_add_str (OUT, "=>");	                \
+        			else						                                \
+		        		cherokee_buffer_add_str (OUT, ":");	                    \
+        			if (w->pretty)					                            \
+		        		cherokee_buffer_add_str (OUT, " ");	                    \
+                }                                                               \
+            }                                                                   \
+	} while(0);
 
-#define ADD_WHITE							\
-	do {								\
-		unsigned int i;						\
-		if (w->pretty) {					\
-			if (CS != dwriter_dict_val) {			\
-				for (i=0; i<w->depth; i++)		\
-					cherokee_buffer_add_str (OUT, "  "); \
-			}						\
-		}							\
+#define ADD_WHITE							                                    \
+	do {								                                        \
+		unsigned int i;					                                    	\
+		if (w->pretty && w->lang != dwriter_xmlrpc) {					        \
+			if (CS != dwriter_dict_val) {			                            \
+				for (i=0; i<w->depth; i++)		                                \
+					cherokee_buffer_add_str (OUT, "  ");                        \
+			}						                                            \
+		}							                                            \
 	} while(0)
 
-#define ADD_END							\
-	do {							\
-		switch(CS) {					\
-		case dwriter_start:				\
-			CS = dwriter_complete;			\
-			break;					\
-		case dwriter_dict_start:			\
-		case dwriter_dict_key:				\
-			CS = dwriter_dict_val;			\
-			break;					\
-		case dwriter_list_start:			\
-			CS = dwriter_list_in;			\
-			break;					\
-		case dwriter_dict_val:				\
-			CS = dwriter_dict_key;			\
-			break;					\
-		default:					\
-			break;					\
-		}						\
+#define ADD_END							                                        \
+    if (w->lang == dwriter_xmlrpc) {                                            \
+        switch (CS) {                                                           \
+            case dwriter_dict_key:                                              \
+				cherokee_buffer_add_str (OUT, "</name>");                       \
+                break;                                                          \
+            case dwriter_dict_val:                                              \
+            case dwriter_list_in:                                               \
+				cherokee_buffer_add_str (OUT, "</value>");                      \
+            default:                                                            \
+                break;                                                          \
+        }                                                                       \
+    }                                                                           \
+                                                                                \
+	do {							                                            \
+		switch(CS) {		                                                    \
+		case dwriter_start:	                                                    \
+			CS = dwriter_complete;	                                            \
+			break;			                                                    \
+		case dwriter_dict_start:			                                    \
+		case dwriter_dict_key:				                                    \
+			CS = dwriter_dict_val;			                                    \
+			break;					                                            \
+		case dwriter_list_start:			                                    \
+			CS = dwriter_list_in;			                                    \
+			break;					                                            \
+		case dwriter_dict_val:				                                    \
+			CS = dwriter_dict_key;			                                    \
+			break;					                                            \
+		default:					                                            \
+			break;					                                            \
+		}						                                                \
 	} while(0)
 
-#define ADD_NEW_LINE					\
-	if ((w->pretty) && (CS == dwriter_complete))	\
-		cherokee_buffer_add_str (OUT, "\n")
+#define ADD_NEW_LINE                                                            \
+    if (CS == dwriter_complete) {                                               \
+        if (w->lang == dwriter_xmlrpc) {                                        \
+            if (w->pretty)                                                      \
+                cherokee_buffer_add_str (OUT, "\t");                            \
+            cherokee_buffer_add_str (OUT, "</member>");                         \
+        }                                                                       \
+    	if (w->pretty)                                                          \
+    		cherokee_buffer_add_str (OUT, "\n");                                \
+    }
 
 
-#define ENSURE_NOT_KEY				\
-	if (CS == dwriter_dict_key)		\
+#define ENSURE_NOT_KEY			                                                \
+	if (CS == dwriter_dict_key)                                                 \
 		return ret_error
 
-#define ENSURE_VALID_STATE					\
-	if ((CS == dwriter_error) || (CS == dwriter_error))	\
+#define ENSURE_VALID_STATE			                                            \
+	if ((CS == dwriter_error) || (CS == dwriter_error))                         \
 		return ret_error
 
-#define INCREMENT_DEPTH				\
-	w->depth += 1;				\
-	if (w->depth >= DWRITER_STACK_LEN)	\
+#define INCREMENT_DEPTH		                                                    \
+	w->depth += 1;				                                                \
+	if (w->depth >= DWRITER_STACK_LEN)	                                        \
 		return ret_error
 
 
@@ -186,8 +220,11 @@
 {
 	ENSURE_VALID_STATE; ENSURE_NOT_KEY;
 	ADD_SEP; ADD_WHITE;
-	
-	cherokee_buffer_add_va (OUT, "%lu", l);
+    
+    if (w->lang == dwriter_xmlrpc) {
+	    cherokee_buffer_add_va (OUT, "<int>%lu</int>", l);
+    } else
+	    cherokee_buffer_add_va (OUT, "%lu", l);
 
 	ADD_END; ADD_NEW_LINE;
 	return ret_ok;
@@ -207,7 +244,12 @@
 	if (re <= 0)
 		return ret_error;
 
-	cherokee_buffer_add (OUT, tmp, re);
+    if (w->lang == dwriter_xmlrpc) {
+	    cherokee_buffer_add_str (OUT, "<double>");
+	    cherokee_buffer_add (OUT, tmp, re);
+	    cherokee_buffer_add_str (OUT, "</double>");
+    } else
+	    cherokee_buffer_add (OUT, tmp, re);
 
 	ADD_END; ADD_NEW_LINE;
 	return ret_ok;
@@ -218,9 +260,14 @@
 {
 	ENSURE_VALID_STATE; ENSURE_NOT_KEY;
 	ADD_SEP; ADD_WHITE;
+    
+    if (w->lang == dwriter_xmlrpc) {
+	    cherokee_buffer_add_str (OUT, "<int>");
+	    cherokee_buffer_add (OUT, s, len);
+	    cherokee_buffer_add_str (OUT, "</int>");
+    } else
+    	cherokee_buffer_add (OUT, s, len);
 
-	cherokee_buffer_add (OUT, s, len);
-
 	ADD_END; ADD_NEW_LINE;
 	return ret_ok;
 }
@@ -231,13 +278,35 @@
 	ENSURE_VALID_STATE;
 	ADD_SEP; ADD_WHITE;
 
-	cherokee_buffer_add_str (OUT, "\"");
+    if (w->lang == dwriter_xmlrpc) {
+        cherokee_buffer_t buf = CHEROKEE_BUF_INIT;
+        
+        cherokee_buffer_add (&buf, s, len);
 
-	escape_string (w->tmp, s, len);
-	cherokee_buffer_add (OUT, w->tmp->buf, w->tmp->len);
+        /* XML Encoding, as you see with &, sequence matters! */
+        cherokee_buffer_replace_string(&buf, "&", 1, "&amp;", 5); 
+        cherokee_buffer_replace_string(&buf, "<", 1, "&lt;", 4); 
+        cherokee_buffer_replace_string(&buf, ">", 1, "&gt;", 4); 
+        cherokee_buffer_replace_string(&buf, "'", 1, "&apos;", 6); 
+        cherokee_buffer_replace_string(&buf, "\"", 1,"&quot;", 6); 
 
-	cherokee_buffer_add_str (OUT, "\"");
+        if (CS != dwriter_dict_key) {
+	        cherokee_buffer_add_str (OUT, "<string>");
+	        cherokee_buffer_add_buffer (OUT, &buf);
+	        cherokee_buffer_add_str (OUT, "</string>");
+        } else
+	        cherokee_buffer_add_buffer (OUT, &buf);
+        
+        cherokee_buffer_mrproper(&buf);
+    } else {
+        cherokee_buffer_add_str (OUT, "\"");
 
+    	escape_string (w->tmp, s, len);
+    	cherokee_buffer_add (OUT, w->tmp->buf, w->tmp->len);
+
+    	cherokee_buffer_add_str (OUT, "\"");
+    }
+
 	ADD_END; ADD_NEW_LINE;
 	return ret_ok;
 }
@@ -262,6 +331,9 @@
 	case dwriter_ruby:
 		cherokee_buffer_add_str (OUT, "nil");
 		break;
+    case dwriter_xmlrpc:
+        cherokee_buffer_add_str (OUT, "<nil/>");
+        break;
 	default:
 		SHOULDNT_HAPPEN;
 	}
@@ -288,6 +360,11 @@
 	case dwriter_php:
 		cherokee_buffer_add_str (OUT, b ? "TRUE" : "FALSE");
 		break;
+    case dwriter_xmlrpc:
+        cherokee_buffer_add_str (OUT, "<boolean>");
+        cherokee_buffer_add_str (OUT, b ? "1" : "0");
+        cherokee_buffer_add_str (OUT, "</boolean>");
+        break;
 	default:
 		SHOULDNT_HAPPEN;
 	}
@@ -315,6 +392,9 @@
 	case dwriter_php:
 		cherokee_buffer_add_str (OUT, "array(");
 		break;
+    case dwriter_xmlrpc:
+        cherokee_buffer_add_str (OUT, "<struct>");
+        break;
 	default:
 		SHOULDNT_HAPPEN;
 	}
@@ -347,6 +427,9 @@
 	case dwriter_php:
 		cherokee_buffer_add_str (OUT, ")");
 		break;
+    case dwriter_xmlrpc:
+        cherokee_buffer_add_str (OUT, "</struct>");
+        break;
 	default:
 		SHOULDNT_HAPPEN;
 	}
@@ -374,6 +457,11 @@
 	case dwriter_php:
 		cherokee_buffer_add_str (OUT, "array(");
 		break;
+    case dwriter_xmlrpc:
+        cherokee_buffer_add_str (OUT, "<array>");
+        if (w->pretty)
+            cherokee_buffer_add_str (OUT, "\n\t");
+        cherokee_buffer_add_str (OUT, "<data>");
 	default:
 		SHOULDNT_HAPPEN;
 	}
@@ -406,6 +494,13 @@
 	case dwriter_php:
 		cherokee_buffer_add_str (OUT, ")");
 		break;
+    case dwriter_xmlrpc:
+        if (w->pretty)
+            cherokee_buffer_add_str (OUT, "\t");
+        cherokee_buffer_add_str (OUT, "</data>");
+        if (w->pretty)
+            cherokee_buffer_add_str (OUT, "\n");
+        cherokee_buffer_add_str (OUT, "</array>");
 	default:
 		SHOULDNT_HAPPEN;
 	}
Index: dwriter.h
===================================================================
--- dwriter.h	(revision 2231)
+++ dwriter.h	(working copy)
@@ -51,7 +51,8 @@
 	dwriter_json,
 	dwriter_python,
 	dwriter_php,
-	dwriter_ruby
+	dwriter_ruby,
+	dwriter_xmlrpc
 } cherokee_dwriter_lang_t;
 
 typedef struct {
