关于返回数组问题 用xml 串行化吧,自己读取不麻烦吗 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你现在想读取xml里面所有用户[],密码[]? 普通的xml读取方法XmlDocument xmlDoc = new XmlDocument();xmlDoc.Load("XMLFile.xml");XmlNode root = xmlDoc.SelectSingleNode("root");int numberOfAccount = int.Parse(root.SelectSingleNode("IdNum").InnerText);XmlNodeList nodes = root.SelectSingleNode("Account").ChildNodes;UserInfo[] users = new UserInfo[numberOfAccount];for (int i = 0; i < numberOfAccount; i++){ XmlNode elm = nodes[i]; UserInfo user = new UserInfo(){ id = elm["id"].InnerText,password = elm["password"].InnerText }; users[i] = user;}class UserInfo{ public string id { get; set; } public string password { get; set; }} string xml = @"<root> <IdNum>2</IdNum> <Account> <user> <id>sunzhenggo</id> <password>123456</password> </user> <user> <id>mengmeng</id> <password>654321</password> </user> </Account> </root>"; XmlDocument xdoc1 = new XmlDocument(); xdoc1.LoadXml(xml); XmlNodeList lists= xdoc1.SelectNodes("root/Account/user"); Dictionary<string, string> dictUsers = new Dictionary<string, string>(); foreach (XmlNode x in lists) { if (x!=null) { string key = x.SelectSingleNode("id").InnerText; string value = x.SelectSingleNode("password").InnerText; dictUsers.Add(key, value); } } 一个关于反射的问题 怎样为动态生成的LABEL注册CLICK事件?? 再问?arraylise 为何为何?关于水晶报表 怎么修改access视图。 .net程序员,我们在这里等你! C#开发的dll在win2000+asp+.net1.1平台上的错误! 将复制的内容自动粘贴到连续的textbox? winform请问长操作时如何弹出窗口,等长操作完成后自动关闭??? 没分数了,问个简单的问题,好心人帮帮忙 C#图片以流的形式加水印 坐标改怎么设置。 考试管理系统
xmlDoc.Load("XMLFile.xml");
XmlNode root = xmlDoc.SelectSingleNode("root");
int numberOfAccount = int.Parse(root.SelectSingleNode("IdNum").InnerText);
XmlNodeList nodes = root.SelectSingleNode("Account").ChildNodes;UserInfo[] users = new UserInfo[numberOfAccount];
for (int i = 0; i < numberOfAccount; i++)
{
XmlNode elm = nodes[i];
UserInfo user = new UserInfo(){ id = elm["id"].InnerText,password = elm["password"].InnerText };
users[i] = user;
}class UserInfo
{
public string id { get; set; }
public string password { get; set; }
}
<IdNum>2</IdNum>
<Account>
<user>
<id>sunzhenggo</id>
<password>123456</password>
</user>
<user>
<id>mengmeng</id>
<password>654321</password>
</user>
</Account>
</root>";
XmlDocument xdoc1 = new XmlDocument();
xdoc1.LoadXml(xml);
XmlNodeList lists= xdoc1.SelectNodes("root/Account/user"); Dictionary<string, string> dictUsers = new Dictionary<string, string>(); foreach (XmlNode x in lists)
{
if (x!=null)
{
string key = x.SelectSingleNode("id").InnerText;
string value = x.SelectSingleNode("password").InnerText;
dictUsers.Add(key, value);
}
}