Hello, I have an issue I've been beating my head on a little. I have a list that I've made from an xml document and I'm trying to call that list and print it to console and run queries on it. So far nothing I've tried or searched and implemented has worked yet. I'm sure it's something simple I'm missing, maybe you could lend a hand? I've deleted what I tried, it was a mess.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace LinqToXml
{
class LinqToXml
{
static void Main(string[] args)
{
Console.ReadKey();
}
}
public class Plant
{
public string CommonName { get; set; }
public string Zone { get; set; }
}
public class PlantHelper
{
public static List<Plant> GetPlants()
{
XDocument doc = XmlHelper.GetPlantDocument();
var xmlPlants = doc.Descendants("PLANT");
List<Plant> plants = new List<Plant>();
foreach (var p in xmlPlants)
{
Plant plant = new Plant();
plant.CommonName = p.Element("COMMON").Value;
plant.Zone = p.Element("ZONE").Value;
plants.Add(plant);
}
return plants;
}
}
}