C# 如何使用XML类在gridview或listview中显示XML内容?

C# 如何使用XML类在gridview或listview中显示XML内容?,c#,asp.net,xml,class,C#,Asp.net,Xml,Class,我从网上得到了一个XML文件,用在我的学校项目中,这个XML文件来自kongregate,用于在我的网站中嵌入游戏。 xml文件采用元素格式,但gridview和listview需要采用属性格式。 这是xml文件的链接: 我得到一个关于把它变成一个类的建议,所以我做了,但我仍然不知道如何准确地使用它。 这是一节课: using System; using System.Collections.Generic; using System.Linq; using Sy

我从网上得到了一个XML文件,用在我的学校项目中,这个XML文件来自kongregate,用于在我的网站中嵌入游戏。 xml文件采用元素格式,但gridview和listview需要采用属性格式。 这是xml文件的链接:

我得到一个关于把它变成一个类的建议,所以我做了,但我仍然不知道如何准确地使用它。 这是一节课:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;

    /// <summary>
    /// Summary description for Class1
    /// </summary>


    /// <remarks/>
    [System.SerializableAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class gameset
{

    private gamesetGame[] gameField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("game")]
    public gamesetGame[] game
    {
        get
        {
            return this.gameField;
        }
        set
        {
            this.gameField = value;
        }
    }
}

/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class gamesetGame
{

    private uint idField;

    private string titleField;

    private string thumbnailField;

    private System.DateTime launch_dateField;

    private string categoryField;

    private string featured_imageField;

    private string[] screenshotField;

    private string flash_fileField;

    private ushort widthField;

    private ushort heightField;

    private string urlField;

    private string descriptionField;

    private string instructionsField;

    private string developer_nameField;

    private uint gameplaysField;

    private decimal ratingField;

    private ushort id1Field;

    /// <remarks/>
    public uint id
    {
        get
        {
            return this.idField;
        }
        set
        {
            this.idField = value;
        }
    }

    /// <remarks/>
    public string title
    {
        get
        {
            return this.titleField;
        }
        set
        {
            this.titleField = value;
        }
    }

    /// <remarks/>
    public string thumbnail
    {
        get
        {
            return this.thumbnailField;
        }
        set
        {
            this.thumbnailField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(DataType = "date")]
    public System.DateTime launch_date
    {
        get
        {
            return this.launch_dateField;
        }
        set
        {
            this.launch_dateField = value;
        }
    }

    /// <remarks/>
    public string category
    {
        get
        {
            return this.categoryField;
        }
        set
        {
            this.categoryField = value;
        }
    }

    /// <remarks/>
    public string featured_image
    {
        get
        {
            return this.featured_imageField;
        }
        set
        {
            this.featured_imageField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("screenshot")]
    public string[] screenshot
    {
        get
        {
            return this.screenshotField;
        }
        set
        {
            this.screenshotField = value;
        }
    }

    /// <remarks/>
    public string flash_file
    {
        get
        {
            return this.flash_fileField;
        }
        set
        {
            this.flash_fileField = value;
        }
    }

    /// <remarks/>
    public ushort width
    {
        get
        {
            return this.widthField;
        }
        set
        {
            this.widthField = value;
        }
    }

    /// <remarks/>
    public ushort height
    {
        get
        {
            return this.heightField;
        }
        set
        {
            this.heightField = value;
        }
    }

    /// <remarks/>
    public string url
    {
        get
        {
            return this.urlField;
        }
        set
        {
            this.urlField = value;
        }
    }

    /// <remarks/>
    public string description
    {
        get
        {
            return this.descriptionField;
        }
        set
        {
            this.descriptionField = value;
        }
    }

    /// <remarks/>
    public string instructions
    {
        get
        {
            return this.instructionsField;
        }
        set
        {
            this.instructionsField = value;
        }
    }

    /// <remarks/>
    public string developer_name
    {
        get
        {
            return this.developer_nameField;
        }
        set
        {
            this.developer_nameField = value;
        }
    }

    /// <remarks/>
    public uint gameplays
    {
        get
        {
            return this.gameplaysField;
        }
        set
        {
            this.gameplaysField = value;
        }
    }

    /// <remarks/>
    public decimal rating
    {
        get
        {
            return this.ratingField;
        }
        set
        {
            this.ratingField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute("id")]
    public ushort id1
    {
        get
        {
            return this.id1Field;
        }
        set
        {
            this.id1Field = value;
        }
    }
}

您能告诉我如何在ListView中显示数据吗?或者您可以将我的xml文件从元素转换为属性吗?

您需要将文件更改为属性,然后在反序列化xml文件后,您有一个列表,然后将其绑定到listview 就像任何数据一样

 YourListView.DataSource = theListOfXmlItems;
 YourListView.DataBind();

你可以找到一个简单的教程

我可以通过改变我的课程使它生效。 我前面的类就是通过使用特殊的复制xml到类中得到的类。 我认为我写它的方式就是将字段更改为属性

这是一节课

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Serialization;

/// <summary>
/// Summary description for GameXML
/// </summary>
[XmlRoot("gameset")]
public class GameSet
{
[XmlElement("game")]
public List<Game> Game { get; set; }
}
[XmlRoot("game")]
public class Game
{
[XmlElement("id")]
public int ID { get; set; }
[XmlElement("title")]
public string Title { get; set; }
[XmlElement("thumbnail")]
public string Thumbnail { get; set; }
[XmlElement("launch_date")]
public string Launch { get; set; }
[XmlElement("category")]
public string Category { get; set; }
[XmlElement("flash_file")]
public string Flash { get; set; }
[XmlElement("width")]
public string Width { get; set; }
[XmlElement("height")]
public string Height { get; set; }
[XmlElement("url")]
public string Url { get; set; }
[XmlElement("description")]
public string Description { get; set; }
[XmlElement("instructions")]
public string Instructions { get; set; }
[XmlElement("developer_name")]
public string Developer_name{ get; set; }
[XmlElement("gameplays")]
public string Gameplays { get; set; }
[XmlElement("rating")]
public string Rating { get; set; }


}