1.XML解析
a)XML格式
<root>
<netstation id=””>
<devicetype id=””>
<device id=””>
<item id=”” value=””>
</item>
<device>
<devicetype>
<netstation>
</root>
b)输入:变电站(netstation)名、设备类型(devicetype)、设备ID(device)
c)输出:Hashtable键=XML-item-id;值=XML-item-value;
如能帮助,感激不尽,谢谢
namespace XML读取
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string userName = "";
string pwd = "";
bool valid = false;
private void label1_Click(object sender, EventArgs e)
{
XmlDocument myXml = new XmlDocument();
myXml.Load("user.xml");
XmlNode users = myXml.DocumentElement;
foreach (XmlNode node in users.ChildNodes)
{
if (node.Name == "user")
{
foreach (XmlNode user in node.ChildNodes)
{
switch (user.Name)
{
case "userName":
userName = user.InnerText;
break;
case "userPasw":
pwd = user.InnerText;
break;
}
if ((userName == txtName.Text.Trim()) && (pwd == txtPwd.Text.Trim()))
{
valid = true;
}
}
}
}
if (valid == true)
{
MessageBox.Show("登录成功!");
}
else
{
MessageBox.Show("登录失败!");
}
}
}
XML文件:
<?xml version="1.0" encoding="utf-8"?>
<users>
<user id="1">
<userName>cxf</userName>
<userPasw>001</userPasw>
</user>
<user id="2">
<userName>1233</userName>
<userPasw>123</userPasw>
</user>
</users>
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息