Refactored generation of XML.