I sometimes have the same problem with xhtml. Most likely you’ll need an external tool.
In my case I use an external tool called htmltidy. Emeditor doesn’t seem to have integrated such a tool.
Similar tools for xml exist; google for example lists:
Hope this helps.