Create a webapplication(asp.net application ) using visual studio. Now create the below class
[Serializable]
public class patient
{
private static patient p;
private int _age;
public int Age
{
get
{
return _age;
}
set
{
_age = value;
}
}
private patient()
{
}
public static patient getPatientObject()
{
if (p == null)
{
p = new patient(); return p;
}
else
{
return p;
}
}
public static void SerializeToXML()
{
//Note: XmlSerializer is a Protected class
patient pat = new patient();
XmlSerializer serializer = new XmlSerializer(typeof(patient));
TextWriter textWriter = new StreamWriter(@"C:\serializedpatient.xml");
serializer.Serialize(textWriter, pat);
textWriter.Close();
}
public static patient DeserializeFromXml()
{
TextReader tr=new StreamReader(@"c:\serializedpatient.xml");
XmlSerializer serializer = new XmlSerializer(typeof(patient));
patient p=(patient)serializer.Deserialize(tr);
return p;
}
}
Next Steps: 1. Now Create a .aspx page with name SerializationSample.aspx
2.Create 2 Buttons with name Serialize( button id=btnSerialize) De-Serialize ( button id=btnDeserialize)
3.Create handlers for these two buttons. Call the methods "patient.SerializeToXML(); " and "patient.DeserializeFromXml();" from the clickeventhandler methods btnSerialize_click,btnDeserialize_click respectively.
For Best Android Training Click Here:Android training in Bangalore
[Serializable]
public class patient
{
private static patient p;
private int _age;
public int Age
{
get
{
return _age;
}
set
{
_age = value;
}
}
private patient()
{
}
public static patient getPatientObject()
{
if (p == null)
{
p = new patient(); return p;
}
else
{
return p;
}
}
public static void SerializeToXML()
{
//Note: XmlSerializer is a Protected class
patient pat = new patient();
XmlSerializer serializer = new XmlSerializer(typeof(patient));
TextWriter textWriter = new StreamWriter(@"C:\serializedpatient.xml");
serializer.Serialize(textWriter, pat);
textWriter.Close();
}
public static patient DeserializeFromXml()
{
TextReader tr=new StreamReader(@"c:\serializedpatient.xml");
XmlSerializer serializer = new XmlSerializer(typeof(patient));
patient p=(patient)serializer.Deserialize(tr);
return p;
}
}
Next Steps: 1. Now Create a .aspx page with name SerializationSample.aspx
2.Create 2 Buttons with name Serialize( button id=btnSerialize) De-Serialize ( button id=btnDeserialize)
3.Create handlers for these two buttons. Call the methods "patient.SerializeToXML(); " and "patient.DeserializeFromXml();" from the clickeventhandler methods btnSerialize_click,btnDeserialize_click respectively.
For Best Android Training Click Here:Android training in Bangalore