C# 读取XML文件信息到listView
如题,怎么样读取XML文件里面的信息读取出来并显示到listView中,以下是我的XML文件里面的信息(以后还会对XML文件添加信息),先谢谢各位啦<?xmlversio...
如题,怎么样读取XML文件里面的信息读取出来并显示到listView中,以下是我的XML文件里面的信息(以后还会对XML文件添加信息),先谢谢各位啦
<?xml version="1.0" encoding="utf-8"?>
<root>
<group>
<classItem>
<Class>A101</Class>
<IP>172.26.21.110</IP>
<Subnet>255.255.255.0</Subnet>
<Gateway>172.26.21.254</Gateway>
<Dns1>172.16.3.3</Dns1>
<Dns2>172.16.3.4</Dns2>
</classItem>
<classItem>
<Class>A102</Class>
<IP>172.26.22.110</IP>
<Subnet>255.255.255.0</Subnet>
<Gateway>172.26.22.254</Gateway>
<Dns1>172.16.3.3</Dns1>
<Dns2>172.16.3.4</Dns2>
</classItem>
<classItem>
<Class>AG02</Class>
<IP>172.26.21.110</IP>
<Subnet>255.255.255.0</Subnet>
<Gateway>172.26.21.254</Gateway>
<Dns1>172.16.3.3</Dns1>
<Dns2>172.16.3.4</Dns2>
</classItem>
<classItem>
<Class>A312</Class>
<IP>172.26.55.3</IP>
<Subnet>255.255.255.0</Subnet>
<Gateway>172.26.55.254</Gateway>
<Dns1>172.16.3.3</Dns1>
<Dns2>172.16.3.4</Dns2>
</classItem>
</group>
</root>
不太懂,代码怎么写? 展开
<?xml version="1.0" encoding="utf-8"?>
<root>
<group>
<classItem>
<Class>A101</Class>
<IP>172.26.21.110</IP>
<Subnet>255.255.255.0</Subnet>
<Gateway>172.26.21.254</Gateway>
<Dns1>172.16.3.3</Dns1>
<Dns2>172.16.3.4</Dns2>
</classItem>
<classItem>
<Class>A102</Class>
<IP>172.26.22.110</IP>
<Subnet>255.255.255.0</Subnet>
<Gateway>172.26.22.254</Gateway>
<Dns1>172.16.3.3</Dns1>
<Dns2>172.16.3.4</Dns2>
</classItem>
<classItem>
<Class>AG02</Class>
<IP>172.26.21.110</IP>
<Subnet>255.255.255.0</Subnet>
<Gateway>172.26.21.254</Gateway>
<Dns1>172.16.3.3</Dns1>
<Dns2>172.16.3.4</Dns2>
</classItem>
<classItem>
<Class>A312</Class>
<IP>172.26.55.3</IP>
<Subnet>255.255.255.0</Subnet>
<Gateway>172.26.55.254</Gateway>
<Dns1>172.16.3.3</Dns1>
<Dns2>172.16.3.4</Dns2>
</classItem>
</group>
</root>
不太懂,代码怎么写? 展开
展开全部
XmlDocument xdoc = new XmlDocument();
string xmlpath = "";//xml路径
xdoc.Load(xmlpath);
XmlNodeList list = xdoc.SelectNodes("//root/group/classItem");
foreach (XmlNode xn in list )
{
string class=xn.ChildNodes.Item(0).InnerText;
string ip= xn.ChildNodes.Item(1).InnerText;
}
剩下自己写了
string xmlpath = "";//xml路径
xdoc.Load(xmlpath);
XmlNodeList list = xdoc.SelectNodes("//root/group/classItem");
foreach (XmlNode xn in list )
{
string class=xn.ChildNodes.Item(0).InnerText;
string ip= xn.ChildNodes.Item(1).InnerText;
}
剩下自己写了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询