c# 读取XmL文件

一.读取

using System.Xml;
public static string GetOwnerID(string company, string factory)
{
    string result = string.Empty;
    XmlNodeList xmlNodeList = MappingXmlDoc.SelectNodes("/MAPPINGS/ITEM");
    if (xmlNodeList != null && xmlNodeList.Count > 0)
    {
        for (int i = 0; i < xmlNodeList.Count; i++)
        {
            if (xmlNodeList.Item(i).Attributes["S_COMPANY"].Value == company && xmlNodeList.Item(i).Attributes["S_FACTORY"].Value == factory)
            {
                result = xmlNodeList.Item(i).Attributes["OWNER_ID"].Value;
                break;
            }
        }
    }
    return result;
}

二.注意点,如果有特殊字符
App.config 实际上是 xml 文件,在标准 xml 文件中特殊字符要进行 HTML 转义,规则如下:
&        &
'         '
"        "
>       >
<       <

你可能感兴趣的:(编程体验,c#)