XML Serialization and Deserialization in C#

Posted by SOF User on Stack Overflow See other posts from Stack Overflow or by SOF User
Published on 2011-02-22T07:11:44Z Indexed on 2011/02/22 7:25 UTC
Read the original article Hit count: 225

Filed under:
|
|
<job id="ID00004" name="PeakValCalcO">
  <uses file="Seismogram_FFI_0_1_ID00003.grm" link="input" />
  <uses file="PeakVals_FFI_0_1_ID00003.bsa" link="output" />
</job>
<job id="ID00005" name="SeismogramSynthesis" >
  <uses file="FFI_0_1_txt.variation-s07930-h00000" link="input" />
  <uses file="Seismogram_FFI_0_1_ID00005.grm" link="output" />
</job>

Let say I have this XML I want to convert into .net Object how can do this i tried it but it doesn't work correct...

public class jobs : List<job> { }

    public class job
    {
        public string id { get; set; }
        public string name { get; set; }
        public List<uses> Files { get; set; }
    }
    public class uses
    {
        public string file { get; set; }
        public string link { get; set; }
    }



 private void Form1_Load(object sender, EventArgs e)
        {

           XmlSerializer serializer = new XmlSerializer(typeof(jobs)); 
           TextReader tr = new StreamReader("CyberShake_100.xml"); 
           job b = (job)serializer.Deserialize(tr); 
           tr.Close(); 
    }

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET