Deserialize XML into Class

Posted by Ajay.Kalol under C# on 8/29/2012 | Points: 10 | Views : 1855 | Status : [Member] | Replies : 0
I have XML file with Multiple Child node..Like.

<comm>  
<operator>admin</operator>
<gender>Female</gender>
<desc_info>
<desc>
<description index="1" group="0">
<name>ajay</name>
<location>ashjfkk</location>
<chemical>H2s</chemical>
<amount>45 ltr</amount>
<status>liquid</status>
</description>
</desc>
</desc_info>
</comm>


I want to Deserialize this XML in Class file. class is like below :

 [Serializable]
[XmlRoot(ElementName = "comm")]
public class Comm
{
public Comm() { }

public string Operator { get; set;}
public string gender { get; set; }

}


[Serializable]
[XmlRoot(ElementName = "desc_info")]
public class desc_info
{
public hazmatinfo objhazmatinfo { get; set; }
}

[Serializable]
[XmlRoot(ElementName = "desc")]
public class desc
{
public hazmat objhazmat { get; set; }
}

[Serializable]
[XmlRoot(ElementName = "description")]
public class description
{
public string name { get; set; }
public string location { get; set; }
public string chemical { get; set; }
public string amount { get; set; }
public string status { get; set; }

}
}


I'm serialize XML by followinf Code :

XmlSerializer xmlSerl = new XmlSerializer(clsRec.GetType());
TextReader objTxtRead = new StreamReader(txtXML.Text);
clsRec = (Comm)xmlSerl.Deserialize(objTxtRead);
objTxtRead.Close();


XML deserialize successfully but can't get child node's value.

So what to do in this or new code to get value of child node.
please provide me solution.

Thanks...

Ajay
ajaypatelfromsanthal.blogspot.in



Responses

(No response found.)

Login to post response