如何在C#中将XML文件读入类中?

时间:2014-10-23 22:14:34

标签: c# xml file class io

我一直在尝试将此XML文件(在下面的链接中)读入我创建的类中。但没有运气。有人有任何想法吗? 我有这个由食品组成的xml文件,每个食品都包含国家,ID,名称和描述,类别和价格。我还创建了一个名为data的类,它是我从xml文件读入数据后保存数据的项的父项。我对xml不是很有经验。如果你们能帮助我的话。我会非常感激

// Here is my XML 
//http://i62.tinypic.com/2r4mwzb.jpg
public class Items{ //The class I've created to hold the data from xml 

    public string country {get;set;}
    public int id { get; set; }
    public string name { get; set; }
    public string description { get; set; }
    public string category { get; set; }
    public float price { get; set; } 

    public void print(){
        Console.WriteLine("Country: " + country);
        Console.WriteLine("id: "+ id);
        Console.WriteLine("description: "+ description);
        Console.WriteLine("category: " + category);
        Console.WriteLine("Price: " + price);
    }
}
public class Data{ // Items is a child class of Data 
    public Items [] FoodItemData;
}


public class Program
{
    static void Main(string[] args)
    {

        XmlTextReader reader = new XmlTextReader("FoodItemData.xml");

        Console.ReadLine();
    }
}

0 个答案:

没有答案