If you're building the XML using Linq-to-XML then check out my answer here. It allows you to write code like this:
public ActionResult MyXmlAction()
{
var xml = new XDocument(
new XElement("root",
new XAttribute("version", "2.0"),
new XElement("child", "Hello World!")));
return new XmlActionResult(xml);
}