sure, here is a routine I use for saving favorites:
private void XMLToFavorites()
{
try
{
string sPath = Application.StartupPath + "\\Favorites.xml";
XmlDocument xmlDoc = new XmlDocument();
XmlElement oParent;
// need to create it and the parent node
if (!File.Exists(sPath))
{
XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
// Create the root element
XmlElement rootNode = xmlDoc.CreateElement("Favorites");
xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);
xmlDoc.AppendChild(rootNode);
xmlDoc.Save(sPath);
// should exit here because there is nothing else to do
return;
}
xmlDoc.Load(sPath);
oParent = xmlDoc.DocumentElement;
Favorites = new System.Collections.ArrayList();
XmlNodeList oList = oParent.ChildNodes;
foreach (XmlNode xNode in oList)
{
// add each item here
System.Windows.Forms.ToolStripMenuItem mnuTemp
= new System.Windows.Forms.ToolStripMenuItem(xNode.InnerText);
mnuTemp.Click += new EventHandler(mnuTemp_Click);
mnuTemp.MouseDown += new MouseEventHandler(mnuTemp_MouseDown);
Favorites.Add(mnuTemp);
mnuFavorites.DropDownItems.Add(mnuTemp);
}
}
catch{}
}
// push the selected favorites to an xml file
private void FavoritesToXML()
{
try
{
string sPath = Application.StartupPath + "\\Favorites.xml";
XmlDocument xmlDoc = new XmlDocument();
// delete if it already exists
if (File.Exists(sPath))
{
File.Delete(sPath);
}
XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
// Create the root element
XmlElement rootNode = xmlDoc.CreateElement("Favorites");
xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);
xmlDoc.AppendChild(rootNode);
foreach (ToolStripMenuItem tsItem in mnuFavorites.DropDownItems)
{
XmlNode xNode = xmlDoc.CreateNode(XmlNodeType.Element, "Favorite", "");
xNode.InnerText = tsItem.Text;
rootNode.AppendChild(xNode);
}
xmlDoc.Save(sPath);
}
catch{}
}
although, I did notice I had used the DataSet.WriteXML as you showed earlier when working directly with a dataset object.