xelement 转 List
List<SwipeCardData> CardDataList = new List<SwipeCardData>(); //返回是xelement的集合,首先获得真正的表的节点。使用Nodes.Descendants("Table"),获得指定标签,然后foreach遍历 foreach (XElement el in result.Nodes.Descendants("Table")) { SwipeCardData CardData = new SwipeCardData(); //根据节点循环赋值给SwipeCardData类 foreach (XElement ell in el.Nodes()) { switch (Convert.ToString(ell.Name)) { case "LineID": CardData.ProcessID = ell.Value != "" ? Convert.ToInt32(ell.Value) : 0; break; case "LineDesc": CardData.ProcessName = ell.Value; break; case "StationID": CardData.StationID = ell.Value != "" ? Convert.ToInt32(ell.Value) : 0; break; case "StationDesc": CardData.StationNmae = ell.Value; break; case "UserID": CardData.EmployeeNum = ell.Value; break; case "UserName": CardData.EmployeeName = ell.Value; break; case "StatusDesc": CardData.type = ell.Value != "" ? ell.Value : ""; break; case "RecordTime": CardData.AtWork = Convert.ToDateTime(ell.Value).ToString("yyyy-MM-dd HH:mm:ss.fff"); break; case "ID": CardData.Id = Guid.NewGuid(); break; default: break; } } //添加到数组中 CardDataList.Add(CardData); }