Using XML in the .NET Framework "  Chapter 4 149 the XML file is loaded from the supplied path. Next, a list of category elements is retrieved from the documents using the GetElementsByTagName method in the XmlDocument class. Finally, each category is added to the UI using the addCategory()  method. Creating and Deleting Categories The next step in creating the XML Address Book application is to create your cat- egories.A separate form is created for this in your project called AddCategory.cs, and can be found at www.syngress.com/solutions in the XmlAddressBook folder. The sole purpose of this form is to collect a category name and verify that the name entered is not empty.After it does this, it calls the addCategory() method of the MainForm class, shown in Figure 4.20 and in XMLAddressBook folder at www.syngress.com/solutions. Figure 4.20  The addCategory Method public void addCategory(string name, bool isNew) { this.lstCategories.Items.Add(name); if(isNew) { XmlElement newCat = myDocument.CreateElement("category"); XmlAttribute newName = myDocument.CreateAttribute("name"); newName.Value = name; newCat.Attributes.Append(newName); myDocument.DocumentElement.AppendChild(newCat); } this.clearEntryDetail(); } The first step in this method is to add the requested category to the category list box. If the category is new (if it should be added to the XML document), then a new XmlElement is created and an XmlAttribute is added.You will end up with an XML element that looks like this: <category name="The name parameter"></category> www.syngress.com 155_xml_net_pd_C04.qk  3/6/02  1:57 PM  Page 149