148 Chapter 4 " Using XML in the .NET Framework DialogResult res = openFileDialog1.ShowDialog(); if(res.ToString().ToLower() == "ok") { this.lstCategories.Items.Clear(); this.lstEntries.Items.Clear(); this.loadAddressBook(openFileDialog1.FileName); saveFileDialog1.FileName = openFileDialog1.FileName; } } This method first prompts the user for a valid file to open. After a valid file is opened, the user interface list boxes are cleared and the loadAddressBook() method is called.The loadAddressBook() method is the main method for initializing the user interface. It adds the categories to the category list box and instantiates the class-level XmlDocument that stores the address book. Figure 4.19 shows the code for loadAddressBook(). Figure 4.19  The loadAddressBook() Method private void loadAddressBook(string path) { this.initMenuItems(true); myDocument = new XmlDocument(); myDocument.Load(path); XmlNodeList categories = this.myDocument.GetElementsByTagName("category"); foreach(XmlNode category in categories) { this.addCategory(category.Attributes["name"].Value, false); } } First, the menu items are initialized by calling the initMenuItems method.This method simply enables certain menu items that wouldnt be valid if there were no address book currently loaded. Next, the myDocument variable is instantiated and www.syngress.com Figure 4.18 Continued 155_xml_net_pd_C04.qk  3/6/02  1:57 PM  Page 148