码迷,mamicode.com
首页 > Windows程序 > 详细

C# 读取 XML文件

时间:2017-09-11 21:23:08      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:turn   com   set   blog   读取   nod   list   类型   ati   

技术分享

public static List<XmlData> GetXmlData( string path,string name)
{
List<XmlData> XmlList = new List<XmlData>();
XmlDocument documwent = new XmlDocument();
documwent.Load(path);
XmlNode rootNode = documwent.SelectSingleNode("metalib");
XmlNodeList childNode = rootNode.ChildNodes;
foreach (XmlNode dataNode in childNode)
{
XmlElement xe = (XmlElement)dataNode;
if (xe.GetAttribute("name").ToString() == name)
{
XmlNodeList infoNode = xe.ChildNodes;
foreach(XmlNode data in infoNode)
{
XmlData xmlData = new XmlData();
if (xmlData!=null)
{
XmlElement attribute = (XmlElement)data;
xmlData.Name = attribute.GetAttribute("name").ToString();
xmlData.Type = attribute.GetAttribute("type").ToString();
xmlData.CName = attribute.GetAttribute("cname").ToString();
XmlList.Add(xmlData);
}

}
return XmlList;
}

}
return null;
}
}
public class XmlData
{
/// <summary>
/// 属性名
/// </summary>
private string m_Name = null;
public string Name
{
get { return m_Name; }
set { m_Name = value; }
}
/// <summary>
/// 属性类型
/// </summary>
private string m_Type = null;
public string Type
{
get { return m_Type; }
set { m_Type = value; }
}
/// <summary>
///
/// </summary>
private string m_CName = null;
public string CName
{
get { return m_CName; }
set { m_CName = value; }

}

}

C# 读取 XML文件

标签:turn   com   set   blog   读取   nod   list   类型   ati   

原文地址:http://www.cnblogs.com/zhushuangmei/p/7506614.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!