152 Chapter 4 " Using XML in the .NET Framework The first step in this method is to create the display version of the entry for the entry list box, which is simply the name and telephone number separated by , and add it to the entry list box. If the entry is new (that is, it should be added to the XML document), the entry is added to the XML document. First, we retrieve a reference to the selected category to which we are adding an entry. Next, an entry element is created and the name and phone number attributes are created, given a value, and added to the entry element.This element ends up looking like: <entry name="Name parameter" phoneNumber="Phone Number parameter" /> Finally, the new entry element is added to the list of children of the category, and the entry detail text boxes are cleared to clean up the screen.The next thing to look at is what happens when a user clicks on an item in the category list. When the user clicks on a category, the entries in that category should appear in the entry list box. See Figure 4.23 and the XmlAddressBook folder at www.syngress.com/solutions for the code to do this. Figure 4.23  Filling the Entries List Box private void lstCategories_Click(object sender, System.EventArgs e) { if(this.lstCategories.SelectedItems.Count > 0) { string category = this.lstCategories.SelectedItems[0].Text; string xpath = "/addressBook/category[@name='" + category + "']/entry"; this.lstEntries.Items.Clear(); XmlNodeList entries = myDocument.SelectNodes(xpath); foreach(XmlNode entry in entries) { string name = entry.Attributes["name"].Value; string phoneNumber = entry.Attributes["phoneNumber"].Value; this.addEntry(category, name, phoneNumber, false); } this.clearEntryDetail(); } } www.syngress.com 155_xml_net_pd_C04.qk  3/6/02  1:57 PM  Page 152