XML中具有相同名称的特定字符串

时间:2018-04-05 19:56:53

标签: c#

开发人员网站上有一个xml文件(蒸汽更准确)。 我试图从某个游戏中读取统计数据。但是怎么做呢? 所有子文件夹都称为消息。 如果它们被称为messageid12345而另一条消息是message1111,那么它将很简单。但是,如何为子文件夹的同名游戏捕获特定游戏的信息?例如,子文件夹上的游戏:5(appid 50)。 更感谢提前帮助)

XmlDocument doc2 = new XmlDocument();
doc2.Load("http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=123456789&steamid=" + label3.Text + @"&format=xml");
XmlElement root2 = doc1.DocumentElement;
XmlNodeList nodes2 = root.SelectNodes("/response/games/message"); // ????? <----
foreach (XmlNode node in nodes2)
{
    string playedtime = node["playtime_forever"].InnerText;
    rust_playtime.Text = playedtime;
}

XML看起来像这样

&#13;
&#13;
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<response>
<game_count>170</game_count>
<games>
<message>
<appid>10</appid>
<playtime_forever>11620</playtime_forever>
</message>
<message>
<appid>20</appid>
<playtime_forever>0</playtime_forever>
</message>
<message>
<appid>30</appid>
<playtime_forever>0</playtime_forever>
</message>
<message>
<appid>40</appid>
<playtime_forever>0</playtime_forever>
</message>
<message>
<appid>50</appid>
<playtime_forever>0</playtime_forever>
</message>
<message>
<appid>60</appid>
<playtime_forever>0</playtime_forever>
</message>
<message>
<appid>70</appid>
<playtime_forever>0</playtime_forever>
</message>
<message>
<appid>130</appid>
<playtime_forever>0</playtime_forever>
</message>
<message>
<appid>2500</appid>
<playtime_forever>303</playtime_forever>
</message>
</games>
</response>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

我认为,您需要在循环中设置条件,以找到一条消息,其中appid等于您需要的那条消息。或者,您可以将此响应解析为对象,其中包含作为响应列表的消息。然后使用LINQ。

使用此列表