C# 读取 XML文件

2021-08-04 15:55

阅读:660

标签:turn   com   set   blog   读取   nod   list   类型   ati    public static List GetXmlData( string path,string name) { List XmlList = new List(); 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 { /// /// 属性名 /// private string m_Name = null; public string Name { get { return m_Name; } set { m_Name = value; } } /// /// 属性类型 /// private string m_Type = null; public string Type { get { return m_Type; } set { m_Type = value; } } /// /// /// 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


评论


亲,登录后才可以留言!