C# 读取xml文件
参考网址:http://www.cnblogs.com/Hisin/archive/2012/02/27/2370646.html
XmlDocument doc = new XmlDocument();
doc.Load("config.xml"); //加载Xml文件
XmlElement rootElem = doc.DocumentElement; //获取根节点
XmlNodeList personNodes = rootElem.GetElementsByTagName("person"); //获取person子节点集合
foreach (XmlNode node in personNodes)
{
string strName = ((XmlElement)node).GetAttribute("name"); //获取name属性值
Console.WriteLine(strName);
XmlNodeList subAgeNodes = ((XmlElement)node).GetElementsByTagName("age"); //获取age子XmlElement集合
if (subAgeNodes.Count == 1)
{
string strAge = subAgeNodes[0].InnerText;
Console.WriteLine(strAge);
}
}