public static FilmSource readFromXml(String filePath) { FilmSource filmSource = new FilmSource(); XmlDocument doc = new XmlDocument(); doc.Load(filePath); // Loop through each group. foreach (XmlNode group in doc.DocumentElement.ChildNodes) { String uniqueIdGroup, nameGroup, descriptionGroup; XmlNode groupNode = group.FirstChild; uniqueIdGroup = groupNode.InnerText; groupNode = groupNode.NextSibling; nameGroup = groupNode.InnerText; groupNode = groupNode.NextSibling; descriptionGroup = groupNode.InnerText; groupNode = groupNode.NextSibling; FilmGroup filmGroup = new FilmGroup(uniqueIdGroup, nameGroup, descriptionGroup); // Loop through each film. foreach (XmlNode film in groupNode.ChildNodes) { String uniqueIdFilm, titleFilm, descriptionFilm, imagePathFilm; XmlNode filmNode = film.FirstChild; uniqueIdFilm = filmNode.InnerText; filmNode = filmNode.NextSibling; titleFilm = filmNode.InnerText; filmNode = filmNode.NextSibling; descriptionFilm = filmNode.InnerText; filmNode = filmNode.NextSibling; imagePathFilm = filmNode.InnerText; // Add film to group. filmGroup.addFilm(uniqueIdFilm, titleFilm, descriptionFilm, imagePathFilm); } //Add group to source. filmSource.addGroup(filmGroup); } return filmSource; }
public MainWindow() { InitializeComponent(); Debug.WriteLine(path); filmSource = FilmSource.readFromXml(path + @"\filmdata.xml"); }