XML : C#: Unable to Deserialize XML into List

I'm trying to deseralize an XML file that has a list of objects into a C# object. The XML looks similar to this:

  <Job Category="Administration" Title="Senior Human Resource Coordinator">  <Description>    <![CDATA[ Long description of the job goes here. ]]>  </Description>  <ShortDescription>    <![CDATA[ Short description of the job goes here.  ]]>  </ShortDescription>  <Locations>    <Location Salary="$40000">NewYork</Location>    <Location Salary="£35000">London</Location>  </Locations>  <Benefits>Drug, Dental, Optical and Extended Healthcare Benefits</Benefits>  <Jobtype>Full-Time</Jobtype>    

The class so far looks like this, I don't have anything yet for the list of Locations, that is what I'm missing and can't figure out. How to put Locations into a list which has element and attribute data.

  [Serializable]  public class Job  {      [XmlAttribute]      public string Category { get; set; }      [XmlAttribute]      public string Title { get; set; }      [XmlElement]      public string Description { get; set; }      [XmlElement]      public string ShortDescription { get; set; }        [XmlArray("Locations")]      [XmlArrayItem("Location")]      public List<JobLocations> Locations { get; set; }        [XmlElement]      public string Benefits { get; set; }      [XmlElement]      public string Jobtype { get; set; }        public static List<Job> Load( string path )      {          return SerializerSupport.DeserializeList<Job>(Path.Combine( path, "jobs.xml" ) );      }         }        

I figured out how to serialized everything but Locations, any help would be appreciated. Thank you in advance.

No comments:

Post a Comment