朱皮特的博客 自由的飞翔

C#读写XML

2017-09-11
朱皮特
阅读量:

string filename = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, FILENAME_OPTIONS);
XmlDocument xmlDoc = new XmlDocument();
XmlNode root = null;
XmlElement element = null;

try
{
    xmlDoc.Load(filename);
    root = xmlDoc.SelectSingleNode("option");
    foreach (XmlNode item in root.ChildNodes)
    {
        element = (XmlElement)item;
        string name = element.GetAttribute("name");
        string param = element.GetAttribute("param");
        string desc = element.GetAttribute("desc");

        if (string.IsNullOrEmpty(name) == false && string.IsNullOrEmpty(param) == false)
        {
            //...
        }

    }//end for

}
catch (Exception e)
{
    bRet = false;
    throw e;
}

Comments

Content