XmlDocument doc = new XmlDocument(); doc.Load("students.xml"); foreach (XmlNode node in doc.SelectNodes("/students/student")) { string xml_studentnumber = node.SelectSingleNode("student_number").InnerText; string xml_password = node.SelectSingleNode("password").InnerText; if (xml_studentnumber == username && xml_password == password) { found = 1; // hide fail elements fail_image.Visible = false; fail_label.Visible = false; StoredData.studentnumber = username; main main = new main(); main.Show(); this.Hide(); } }