When a user clicks a "Check Out" button, their name is supposed to be removed from an xml file, and subsequently removed from a list box, indicating they left a meeting. However,I have encountered Null Reference Exceptions during debugging because _xmlNode is null. From my research on this issue, it seems the problem lies in the declaration of XmlDocument and the passing of its instance _xmlDocument to deleteAttendee(). However, I believe that I declared _xmlDocument correctly, and am having difficulty finding where my strategy went off track. I would appreciate any pointers that could help steer me back in the right direction. Thanks!
protected void checkOutButton_Click(object sender, EventArgs e) { string fileName = Server.MapPath("~/App_Data/attendees.xml"); XmlTextReader _xmlTextReader = new XmlTextReader(fileName); XmlDocument _xmlDocument = new XmlDocument(); _xmlDocument.Load(_xmlTextReader); _xmlTextReader.Close(); deleteAttendee(inMeetingListBox.SelectedItem.Text, fileName, _xmlDocument); inMeetingListBox.Items.Remove(inMeetingListBox.SelectedItem); } static void deleteAttendee(string attendeeName, string fileName, XmlDocument xmlDoc) { string test = xmlDoc.DocumentElement.ToString(); XmlElement _xmlElement = xmlDoc.DocumentElement; XmlNode _xmlNode = _xmlElement.SelectSingleNode("attendee[@name='asp']"); _xmlElement.RemoveChild(_xmlNode); xmlDoc.Save(fileName); }