Index: src/xmlformat.c
===================================================================
--- src/xmlformat.c	(revision 5836)
+++ src/xmlformat.c	(working copy)
@@ -67,6 +67,11 @@
 		return FALSE;
 	}
 
+	if(!osync_xmlformat_sort(xmlformat, error)) {
+		osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
+		return FALSE;
+	}
+
 	*output = (char *) xmlformat;
 	*outpsize = osync_xmlformat_size();
 
@@ -303,6 +308,9 @@
 
 	osync_trace(TRACE_ENTRY, "%s(%p, %i)", __func__, data, size, error);
 
+	if (!osync_xmlformat_sort((OSyncXMLFormat *)data, error))
+		goto error;
+
 	fieldlist = osync_xmlformat_search_field((OSyncXMLFormat *)data, attribute, error, NULL);
 	if (!fieldlist)
 		goto error;

