小编Mik*_*893的帖子

C# - 读取XML文件

我正在尝试读取XML文件,以便将数据集成到Windows Phone App中.

我跟着其他一些主题,但是我无法让它工作(我觉得我差点就在这一点但仍然缺少一些东西).

我想读的XML是:

<?xml version="1.0" encoding="utf-8"?>
<items>
    <item value="0">status</item>
    <item value="210">online</item>
    <item value="22h 49m 49s">uptime</item>
    <item value="90">latency</item>
    <item value="423">maxplayers_ever</item>
    <item value="263">maxplayers_week</item>
    <item value="252">maxplayers</item>
</items>
Run Code Online (Sandbox Code Playgroud)

它包含游戏服务器的信息.

我正在从URL读取它,这是我使用的代码:

    public class Item
    {
        public string Name { get; set; }
        public string Value { get; set; }
    }

    private void LoadXMLFile()
    {
        WebClient wc = new WebClient();
        wc.DownloadStringCompleted += HttpsCompleted;
        wc.DownloadStringAsync(new Uri("https://www.forgottenlands.eu/data.xml.php"));
    }

    private void HttpsCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        if (e.Error == null)
        {
            this.Items.Add(new ItemViewModel() { LineOne = "TEST …
Run Code Online (Sandbox Code Playgroud)

c# xml linq xml-parsing

2
推荐指数
1
解决办法
7605
查看次数

标签 统计

c# ×1

linq ×1

xml ×1

xml-parsing ×1