This is a discussion on XML Serialization Using C#... within the C# Programming forums, part of the Software Development category; Hi, Could any one about explain xml serialisation...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Object Serialization is a process through which an object's state is transformed into some serial data format, such as XML or a binary format. For example, you can serialize an object and transport it over the Internet using HTTP between a client and a server. On the other end, deserialization reconstructs the object from the stream. XML was designed to be a technology for data exchange across heterogeneous systems. It can be easily transmitted between distributed components because of its platform independence and its simple, text-based, self-describing format. |
| |||
| Some good uses for serialization/deserialization include: * Storing user preferences in an object. * Maintaining security information across pages and applications. * Modification of XML documents without using the DOM. * Passing an object from one application to another. * Passing an object from one domain to another. * Passing an object through a firewall as an XML string. |
| |||
| Suppose we have an object defined and instantiated as shown below: class Person { private String personName; private Int32 personAge; public String Name { get { return personName; } set { personName = value; } } public Int32 Age { get { return personAge; } set { personAge = value; } } } |
| |||
| Demo class having public properties Instantiation of the class is shown below: Person oPerson = new Person(); oPerson.Name = "Anthony"; oPerson.Age = 38; Let's say that for some reason, we wanted to save a copy of this object just as it is at this very moment. We could serialize it as an XML document that would look something like this: <Person> <Name>Anthony</Name> <Age>38</Age> </Person> Then, at some later time when we needed to use the object again, we could just deserialize it and have our object restored to us just as it was at the moment we serialized it. |
| |||
| However XML serialization follows certain rules and the classes defined by us have to conform to these rules. 1. XML serialization serializes only the public fields and property values of an object into an XML stream. 2. XML serialization does not include type information. 3. XML serialization requires a default constructor to be declared in the class that is to be serialized. 4. XML serialization requires all properties that are to be serialized as read write properties. Read only properties are not serialized. |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What is serialization | vadivelanvaidyanathan | ASP and ASP.NET Programming | 2 | 09-11-2007 09:30 AM |
| Serialization and Deserialization | vigneshgets | VB.NET Programming | 2 | 08-21-2007 12:41 AM |
| Serialization and Encoding | vigneshgets | C# Programming | 1 | 08-01-2007 11:37 PM |
| Serialization and deserialization | sivakumar | Java Programming | 1 | 07-17-2007 05:52 AM |
| Serialization | leoraja8 | Java Programming | 1 | 05-10-2007 08:46 AM |