public XElement Categories() { //XElement root = new XElement("root"); //root.Add(new XElement("element1")); //root.Add(new XElement("element2")); //root.Add(new XAttribute("attribute1", "a value")); XElement categories = new XElement("categories"); foreach (var cat in _category.AllItems()) { var category = new XElement("category"); category.Value = cat.Name; categories.Add(category); } return(categories); }