public static void ExportStars() { List <StarExportDto> starsDto = StarStore.GetStars(); XDocument xmlDoc = new XDocument(); XElement starsXml = new XElement("Stars"); foreach (var starDto in starsDto) { foreach (var star in starDto.Stars) { XElement starXml = new XElement("Star", new XElement("Name", star.Name), new XElement("Temperature", star.Temperature), new XElement("StarSystem", star.StarSystem)); XElement discoveryInfo = new XElement("DiscoveryInfo", new XAttribute("DiscoveryDate", $"{starDto.DiscoveryDate:yyyy-MM-dd}"), new XAttribute("TelescopeName", starDto.Telescope)); foreach (var astronomer in starDto.Astronomers) { discoveryInfo.Add(new XElement("Astronomer", astronomer.FirstName + " " + astronomer.LastName, new XAttribute("Pioneer", astronomer.Role))); } starXml.Add(discoveryInfo); starsXml.Add(starXml); } } xmlDoc.Add(starsXml); xmlDoc.Save("../../Export/stars.xml"); }
public static void ExportStars() { var stars = StarStore.GetStars(); XDocument starsXml = new XDocument(); XElement starsElement = new XElement("Stars"); foreach (var star in stars) { var newStar = new XElement("Star"); newStar.Add(new XElement("Name", star.Name)); newStar.Add(new XElement("Temperature", star.Temperature)); newStar.Add(new XElement("StarSystem", star.HostStarSystem.Name)); var discoveryInfo = new XElement("DiscoveryInfo"); var discovery = star.DiscoveriesIncludedIn .OrderBy(s => s.DateMade) .FirstOrDefault(); discoveryInfo.Add(new XAttribute("DiscoveryDate", discovery.DateMade.ToString())); discoveryInfo.Add(new XAttribute("TelescopeName", discovery.TelescopeUsed.Name)); newStar.Add(discoveryInfo); var astronomers = new XElement("Astronomers"); } starsXml.Add(starsElement); }