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();
    }
}
4
  • 1
    look into xml serialization Commented Oct 23, 2014 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. Commented Oct 23, 2014 at 22:18
  • SEE BELOW TO GET THE JOB DONE! stackoverflow.com/questions/364253/… Commented Oct 23, 2014 at 22:19
  • sorry i deleted the part of my code where: Data xml = new Data(); Commented Oct 23, 2014 at 22:21

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.