C#读写XML

2017/09/11 program 共 551 字,约 2 分钟
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;
}

文档信息

Search

    Table of Contents