2016-03-04 46 views
-2

我从网上得到了一个XML文件,用于我的学校项目中,这个xml文件是kongregate用于在我的网站中嵌入游戏的文件。 xml文件采用ELEMENT格式,但gridview和listview需要采用ATTRIBUTE格式。 这是xml文件的链接:http://www.kongregate.com/games_for_your_site.xml如何使用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文件从元素转换为属性?

回答

0

你需要改变文件属性,然后反序列化你的XML文件后,你有一个列表,然后你就像任何数据绑定到列表视图 。

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

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

0

我能够让它改变我的课工作。 我之前得到的类是通过使用特殊副本xml来获得的类。 我的思维方式我写它是什么意思Thorarnis(改变字段放入属性)

这是类

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; } 


}