0

I've been trying to read in this XML file ( in the link below) into my class that I've created. but had no luck. Anyone got any ideas ? I have this xml file that is consist of food items each food item is consist of country, id, name, and description, category, and price. I've also created a class called data the is a parent to items to hold the data once I read in the data from the xml file. I am not very experienced in xml. If you guys could help me out. i would be very thankful

// 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();
    }
}
Bovill
  • 1
  • 1
    look into xml serialization – Selman Genç Oct 23 '14 at 22:15
  • 1
    First of all, don't use `new XmlTextReader()` anymore. Use `XmlReader.Create()`. Second, why do you think that code is going to read _anything_ into _any_ class? It doesn't even reference the class? That's not what `XmlReader` does. – John Saunders Oct 23 '14 at 22:18
  • SEE BELOW TO GET THE JOB DONE! http://stackoverflow.com/questions/364253/how-to-deserialize-xml-document – Darshana Oct 23 '14 at 22:19
  • sorry i deleted the part of my code where: Data xml = new Data(); – Bovill Oct 23 '14 at 22:21

0 Answers0