Index: CKEditor/trunk/CHANGES.html
===================================================================
--- CKEditor/trunk/CHANGES.html	(revision 6430)
+++ CKEditor/trunk/CHANGES.html	(revision 6431)
@@ -52,4 +52,5 @@
 		<li><a href="http://dev.ckeditor.com/ticket/6387">#6387</a> : AutoGrow may cause an error when editor instance is destroyed too quickly after height change.</li>
 		<li><a href="http://dev.ckeditor.com/ticket/6901">#6901</a> : Mixed direction content was not properly respected on a shared toolbar.</li>
+		<li><a href="http://dev.ckeditor.com/ticket/4809">#4809</a> : Table related tags are outputted in wrong order.</li>
 		<li>Updated the following language files:<ul>
 			<li><a href="http://dev.ckeditor.com/ticket/7124">#7124</a> : Czech;</li>
Index: CKEditor/trunk/_source/plugins/htmldataprocessor/plugin.js
===================================================================
--- CKEditor/trunk/_source/plugins/htmldataprocessor/plugin.js	(revision 6430)
+++ CKEditor/trunk/_source/plugins/htmldataprocessor/plugin.js	(revision 6431)
@@ -80,4 +80,7 @@
 
 	var dtd = CKEDITOR.dtd;
+
+	// Define orders of table elements.
+	var tableOrder = [ 'caption', 'colgroup', 'col', 'thead', 'tfoot', 'tbody' ];
 
 	// Find out the list of block-like tags that can contain <br>.
@@ -159,4 +162,15 @@
 
 					return element;
+				},
+
+				// The contents of table should be in correct order (#4809).
+				table : function( element )
+				{
+					var children = element.children;
+					children.sort( function ( node1, node2 )
+								   {
+									   return node1.type == CKEDITOR.NODE_ELEMENT && node2.type == node1.type ?
+											tableOrder.indexOf( node1.name ) > tableOrder.indexOf( node2.name ) ? 1 : -1 : 0;
+								   } );
 				},
 
