I’m very close. I’m ask to delete an entry from an XML FILE if the last name of an ASP TEXT BOX matches to an XML “entry”.
Here is the button script. Please take note of XmlNode PhoneBook line:
protected void deletion_Click(object sender, EventArgs e)
{
XmlDocument document = new XmlDocument();
document.Load(Server.MapPath("~/App_Data/PhoneBook.xml"));
XmlElement root = document.DocumentElement;
XmlNode PhoneBook = document.SelectSingleNode("//event[@lastName='" + txtLastName.Text + "']");
PhoneBook.ParentNode.RemoveChild(PhoneBook);
document.Save(Server.MapPath("~/App_Data/PhoneBook.xml"));
GridView1.DataBind();
}
I keep getting errors, I’m guessing I’m not selecting the correct node in the xml file using SelectSingleNode?
Try this:
You’re trying to filter on an
element, not anattributeso you can’t use the@sign.This XPath returns the 2nd
entryelement (I tested it, it works):