读取xml

List<path> Report = new List<path>();
XmlDocument myCha = new XmlDocument();
try
{
myCha.Load(path);
}
catch (Exception e)
{
if (e != null)
{
return Report;
}
}
myCha.Load(path);
//2.获得根节点
XmlNode node = myCha.DocumentElement;
foreach (XmlNode ShowList in node.ChildNodes)
{
if (ShowList.Attributes["state"].InnerText.ToString().Equals("1"))
{
path report = new path();
foreach (XmlNode work in ShowList.ChildNodes)
{

switch (work.Name)
{

case "ip":
report.ip = work.InnerText;
break;
case "ku":
report.ku= work.InnerText;
break;
case "name":
report.name = work.InnerText;
break;
case "passwrod":
report.passwrod = work.InnerText;
break;
}
}
Report.Add(report);
}
}
return Report;
}

posted @ 2018-05-15 11:07  就爱敲代码  阅读(142)  评论(0编辑  收藏  举报