读取xml

时间:2024-01-22 13:27:35

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;
}