有个方法返回一个XmlDocument对象,值为<Root><Game GameID=\"1\" GameName=\"TestGame\" /></Root> 请问我要怎样才能取出它的GameID和GameName?可能<Root>中有多条记录
解决方案 »
- 表单提交问题
- marquee+datalist问题
- MVC 404问题
- 求救, .net1.1 升级成2.0 后,同样一个sha1加密,却得和1.1到不同的字串
- ╰.Net Framework 2.0交流群 群号:2306894 (参加工作者进)
- 为什么在DataGrid的事件里面取不到它的DataSource?
- Visual Web Developer 2005 框架不能用的问题,顶有分。
- 急,在线等
- 我打算买个asp.net空间,请问我上传后就可以用了吗?
- 200分求可上载的FTP空间.
- TreeView 中怎么调整节点的位置?? 好像 .net 2.0中的TreeView控件没有对应的功能 -_-||
- IUSR_ 计算机名 权限与安全性问题。
string xmlStr = "<Root> <Game GameID=\"1\" GameName=\"TestGame\" /> </Root>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlStr);
XmlNodeList list = doc.SelectNodes("Root/Game");
foreach (XmlNode node in list)
{
string id = node.Attributes["GameID"].Value;
string name = node.Attributes["GameName"].Value;
Console.Write(string.Format("id:{0}; name:{1}", id, name));
}
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlStr);
XmlNodeList list = doc.SelectSingleNode("Root").ChildNodes;
foreach (XmlNode node in list)
{
string id = node.Attributes["GameID"].Value;
string name = node.Attributes["GameName"].Value;
Console.Write(string.Format("id:{0}; name:{1}", id, name));
}