Using XML in the .NET Framework "  Chapter 4 151 be removed. Finally, the category and entry list boxes are cleared, and the entry detail text boxes are cleared. Creating, Editing, and Deleting Entries Now that we have finished with creating and deleting categories, the next step is to be able to add, edit, and delete entries from each category. For adding entries, a form has been created to accept the entry name and telephone number and verify that each is not an empty string (this form is named AddEntry.cs and can be found in the XmlAddressBook folder at After a category has been selected, and an entry name and telephone number have been entered, the addEntry() method of the MainForm class is called.The code for this method can be found in Figure 4.22. Figure 4.22  The addEntry Method public void addEntry(string categoryName, string entryName, string phoneNumber, bool isNew) { string entry = entryName + " -- " + phoneNumber; this.lstEntries.Items.Add(entry); if(isNew) { XmlNode oldCat = myDocument.SelectSingleNode( "/addressBook/category[@name='" + categoryName + "']"); XmlElement newEntry = myDocument.CreateElement("entry"); XmlAttribute newName = myDocument.CreateAttribute("name"); newName.Value = entryName; XmlAttribute newPhone = myDocument.CreateAttribute("phoneNumber"); newPhone.Value = phoneNumber; newEntry.Attributes.Append(newName); newEntry.Attributes.Append(newPhone); oldCat.AppendChild(newEntry); } this.clearEntryDetail(); } 155_xml_net_pd_C04.qk  3/6/02  1:57 PM  Page 151