154 Chapter 4 " Using XML in the .NET Framework Figure 4.24  Continued } else { MessageBox.Show("You must enter a name and a number."); } } After the text boxes have been validated (no empty strings allowed), an XPath expression is built to find the entry the user is editing.The XPath for this looks like: /addressBook/category[@name='Selected Category']/entry[@name='Selected Entry'] Next, the entry element is selected, and its name and phoneNumber attributes are set to what the user entered into the Name and Phone Number text boxes. Finally, the entry in the entry list box is updated to what the user entered. The last feature needed in the XML Address Book is the capability to delete entries. Deleting entries is incredibly similar to everything youve seen so far.The process is simple: Select a category, select an entry, and press the Delete button. The code to delete an entry is shown in Figure 4.25. Figure 4.25  Deleting an Entry private void mnuEntryRemove_Click(object sender, System.EventArgs e) { if(this.lstEntries.SelectedItems.Count > 0) { string category = this.lstCategories.SelectedItems[0].Text; string entry = this.lstEntries.SelectedItems[0].Text; string name = entry.Substring(0, entry.IndexOf(" -- ")); string xpath = "/addressBook/category[@name='" + category + "']/entry[@name='" + name + "']"; XmlNode entryNode = myDocument.SelectSingleNode(xpath); www.syngress.com Continued 155_xml_net_pd_C04.qk  3/6/02  1:57 PM  Page 154