Updated write logic. Added XMLElement to solve issue of including attributes.