private void readFile_Click(object sender, EventArgs e) { try { doc.Load(xml); } catch (Exception ex) { MessageBox.Show(ex.Message); this.readFile.Enabled = false; return; } XmlNode applicants = doc.FirstChild; List <String> data = new List <String>(); foreach (XmlNode applicant in applicants.ChildNodes) { XmlNode personalInfo = applicant.FirstChild; data.Add(String.Format("First Name: {0}", personalInfo.Attributes["FirstName"].Value)); data.Add(String.Format("Last Name: {0}", personalInfo.Attributes["LastName"].Value)); data.Add(String.Format("Age: {0}", personalInfo.Attributes["Age"].Value)); data.Add(String.Format("Email: {0}", personalInfo.Attributes["Email"].Value)); XmlNode address = personalInfo.FirstChild; data.Add(String.Format("Country: {0}", address.Attributes["Country"].Value)); data.Add(String.Format("State: {0}", address.Attributes["State"].Value)); data.Add(String.Format("City: {0}", address.Attributes["City"].Value)); XmlNode phone = address.NextSibling; data.Add(String.Format("Phone Number: {0}", address.InnerText)); XmlNode studentInfo = personalInfo.NextSibling; data.Add(String.Format("FacultyNumber: {0}", studentInfo.Attributes["FacultyNumber"].Value)); data.Add(String.Format("Course: {0}", studentInfo.Attributes["Course"].Value)); XmlNode mainCourse = studentInfo.FirstChild; data.Add(String.Format("Main Course: {0}", mainCourse.InnerText)); XmlNode optionalCourses = mainCourse.NextSibling; if (optionalCourses.ChildNodes.Count > 0) { data.Add("Optional Courses"); } foreach (XmlNode optionalCourse in optionalCourses.ChildNodes) { data.Add(String.Format(" Course Name: {0}", optionalCourse.Attributes["Name"].Value)); data.Add(String.Format(" Credits: {0}", optionalCourse.Attributes["Credits"].Value)); XmlNode professor = optionalCourse.FirstChild; data.Add(String.Format( " Professor: {0} {1}", professor.Attributes["FirstName"].Value, professor.Attributes["LastName"].Value)); } data.Add("---------------------------------"); } readForm readForm = new readForm(); readForm.Show(); readForm.containerInterface = String.Join("\n", data); }
private void readFile_Click(object sender, EventArgs e) { try { doc.Load(xml); } catch (Exception ex) { MessageBox.Show(ex.Message); this.readFile.Enabled = false; return; } XmlNode applicants = doc.FirstChild; List<String> data = new List<String>(); foreach (XmlNode applicant in applicants.ChildNodes) { XmlNode personalInfo = applicant.FirstChild; data.Add(String.Format("First Name: {0}", personalInfo.Attributes["FirstName"].Value)); data.Add(String.Format("Last Name: {0}", personalInfo.Attributes["LastName"].Value)); data.Add(String.Format("Age: {0}", personalInfo.Attributes["Age"].Value)); data.Add(String.Format("Email: {0}", personalInfo.Attributes["Email"].Value)); XmlNode address = personalInfo.FirstChild; data.Add(String.Format("Country: {0}", address.Attributes["Country"].Value)); data.Add(String.Format("State: {0}", address.Attributes["State"].Value)); data.Add(String.Format("City: {0}", address.Attributes["City"].Value)); XmlNode phone = address.NextSibling; data.Add(String.Format("Phone Number: {0}", address.InnerText)); XmlNode studentInfo = personalInfo.NextSibling; data.Add(String.Format("FacultyNumber: {0}", studentInfo.Attributes["FacultyNumber"].Value)); data.Add(String.Format("Course: {0}", studentInfo.Attributes["Course"].Value)); XmlNode mainCourse = studentInfo.FirstChild; data.Add(String.Format("Main Course: {0}", mainCourse.InnerText)); XmlNode optionalCourses = mainCourse.NextSibling; if(optionalCourses.ChildNodes.Count > 0) data.Add("Optional Courses"); foreach(XmlNode optionalCourse in optionalCourses.ChildNodes) { data.Add(String.Format(" Course Name: {0}", optionalCourse.Attributes["Name"].Value)); data.Add(String.Format(" Credits: {0}", optionalCourse.Attributes["Credits"].Value)); XmlNode professor = optionalCourse.FirstChild; data.Add(String.Format( " Professor: {0} {1}", professor.Attributes["FirstName"].Value, professor.Attributes["LastName"].Value)); } data.Add("---------------------------------"); } readForm readForm = new readForm(); readForm.Show(); readForm.containerInterface = String.Join("\n", data); }