Search This Blog

Tuesday, December 28, 2010

Serialization and De-Serialization Example

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

Thursday, December 23, 2010

what is Serialization and when to do it?

Student: What is Serialization?
TechPalle: Serialization is the process of converting an object into a stream. stream can be xml stream or it can be a byte stream.
Student: Why should i do Serialization?
TechPalle: Serialization is required many times in Real time programming.
Below are the examples of when to use Serialization.
Ex 1: In the 3-tier architecture let us say we have BAL,DAL and UI layer. Now assume these projects deployed in three different machines. now i want to get an object of some class from one tier to other tier or application in another computer. So if you want to send objects from one computer to another , you cannot transfer the object in its original form . But you need to convert the object into some form of stream and then send the stream to another computer. Now after receiving the stream then get the object back by DE-serializing the object back from the stream. This is the common situation where you have to do Serialization and De-Serialization. See complete example of Serialization and De serialization in the next article.

Friday, December 10, 2010

Difference between XML and HTML

1.HTML is a presentation language ( What ever elements you create by using HTML user can see thoas as GUI elements in the browser)
2.XML is used especially for storing Data and Transporting the Data
3.Apart from the above fundamental difference there are syntactical differences also.
4.Xml is a strongly typed language and HTML is loosely typed language
Ex: If you miss any ending tag in the XML your document will not be parsed and XML Parser gives you an Error. In case of HTML if you miss any ending tag then also your HTML code will be executed.
5.XML is case sensitive Ex: <Name>and <name>are not same
6.HTML is not case sensitive Ex: <Title>and<title> are same

What is XML

1.XML stands for Extensible mark-up language
2.XML is used for data storage.
3.XML is an easy transporation mechanism , in case of corporate environments usually fire walls will stop the data before enetering into corporate network but xml files can be easily transporated even in presence of fire-walls.
4.XML is a strongly types language ( Means the XML Parser checks the syntax thoroughly if any descripency found the parser through an exception and out put will not be given).
5.But incase of HTML if you have any errors, HTML Parser will still execute your HTML Code.
6.XML is mainly used for Transporatation and Storage.
Palle Technologies providing Best .Net Training http://techpalle.com/net-training-in-bangalore.html

What is XML Parser

1.All xml files or documents will be converted into xml DOM Object by XML Parser.
2.All new browsers will be having XML Parsers.
3.XML DOM is a graphical representation of the nodes in browsers memory.
Ex: Let us say i have below "Students.xml" file .
<Students>
<Student> <Name>Sreepriya</Name> </Student>
<Student><Name>Subhashini</Name></Student>
</Students>
Explanation: Now Parser will read the above xml file and prepare Logical graphs for each and every node just like a tree.Please see the below diagram for how the DOM tree looks like.

XML Assignments

1.What is xml, how the xml will be parsed, who do parsing
2.what is element,node,attribute in xml.
3.Validating the xml file using DTD
4.Sax Parser and DOM Parser
5.What is xml Namespace,CDATA,PCDATA
6.What is XML Island
7.What is XML DOM
8.How to read xml file by using C#
9.How to modify data in xml by using C#
10.What is Xpath
11.What is Xquery

Resources needs to be used is
http://www.w3schools.com/
MSDN Library or Google is the best resource.