private void Load()
{
var xml = new XmlDocument();
xml.Load("XXXX.xml");
var listMaterial = new List<Material>();
var qdNodeList = xml.SelectNodes("/一级节点/二级节点/三级节点/四级节点/五级节点/六级节点/奇迹节点").Cast<XmlNode>().ToList();
foreach (XmlNode qdNode in qdNodeList)
{
var qd = new Dictionary<string, dynamic>();
string dicString = string.Empty;
foreach (XmlAttribute item in qdNode.Attributes)
{
qd[item.Name] = item.Value;
if (item.Name != "MC" && item.Name != "GG" && item.Name != "DW")
dicString += string.Format("\"{0}\":\"{1}\",", item.Name, item.Value);
}
dicString ="{"+ dicString.Remove(dicString.LastIndexOf(","),1)+"}";
Material dy = new Material()
{
Name = qd.ContainsKey("MC") ? qd["MC"].ToString() : "",
Standar = qd.ContainsKey("GG") ? qd["GG"].ToString() : "",
Unit = qd.ContainsKey("DW") ? qd["DW"].ToString() : "",
Parameters = dicString,//JsonConvert.SerializeObject(otherList), /* qd.ContainsKey("DW") ? qd["DW"].ToString() : "",*/
};
listMaterial.Add(dy);
}
return listMaterial;
}
读取xml文件
最新推荐文章于 2023-11-28 09:59:50 发布