using System.Collections.Generic; using System.IO; using System.Xml; using ZJ_BYD.ViewModel; namespace ZJ_BYD.Untils { public class XmlHelper { /// /// 获取系统内置点位 /// /// public static List GetSystemPoints() { //声明XmlDocument对象,并加载XML文件 XmlDocument doc = new XmlDocument(); doc.Load(@"ConfigFile/SystemPoints.xml"); //此处为XML文件的路径 //得到根节点node XmlNode rootNode = doc.SelectSingleNode("SystemPoints"); List xmlPointVMs = new List(); //得到根节点的所有子节点 XmlNodeList pointsNodes = rootNode.ChildNodes; foreach (XmlNode item in pointsNodes) { if (item.Name == "point") { XmlPointVM xmlPointVM = new XmlPointVM(); foreach (XmlNode pointNode in item) { switch (pointNode.Name) { case "PointCode": xmlPointVM.PointCode = pointNode.InnerText; break; case "Address": xmlPointVM.Address = pointNode.InnerText; break; case "PointName": xmlPointVM.PointName = pointNode.InnerText; break; case "DataType": xmlPointVM.DataType = pointNode.InnerText; break; case "Length": xmlPointVM.Length = pointNode.InnerText; break; case "IsSystem": xmlPointVM.IsSystem = bool.Parse(pointNode.InnerText); break; case "IsSaveDb": xmlPointVM.IsSaveDb = bool.Parse(pointNode.InnerText); break; case "IsActive": xmlPointVM.IsActive = bool.Parse(pointNode.InnerText); break; case "IsRealTime": xmlPointVM.IsRealTime = bool.Parse(pointNode.InnerText); break; case "SortIndex": xmlPointVM.SortIndex = int.Parse(pointNode.InnerText); break; case "Remark": xmlPointVM.Remark = pointNode.InnerText; break; } } xmlPointVMs.Add(xmlPointVM); } } return xmlPointVMs; } } }