XML was designed to be a technology for data exchange across heterogeneous systems. You can easily transmit XML between distributed components because of its platform independence and its simple, text-based, self-describing format, yet these features hardly form the basis for a solid programming platform. Text-based data does not enforce type-safety rules. Programmers are much more enticed by object-oriented programming models because each object is of a certain type, so the compiler can warn of potential type problems, and data encapsulated by an object can be eas- ily accessed. The ideal programming environment would use an object-oriented model to build the software but leverage the benefits of XML to communicate between distributed components, over the Internet or Message Queues, for example. This is where XML serialization plays an important role by providing you with the bridge that enables you to seamlessly transform an object to XML and vice versa. |
XML serialization is the process of translating a collection of data into a stream of information. Deserialization is the reverse: translating a stream of information back into the data that originally produced it. Sometimes these processes are called dehydration and rehydration. The System.Xml .Serialization namespace contains classes to create an XML representation for an object or ini- tialize an object directly from XML. Using XML serialization will reduce the amount of code you have to develop for an XML-based data exchange application. You no longer have to parse XML to initialize objects, neither do you have to develop code for objects to persist themselves to XML. After you define what the XML format you use to exchange data looks like, you can quickly develop classes that can automatically store their data to the XML format or objects can be auto- matically created from XML. |
This chapter focuses on the serialization features of .NET framework that are used to serialize objects to an XML-based representation and then deserializing the XML back into objects. You also learn how to customize the output generated by the serialization of objects so their XML represen- tation will map to a given XML format. By the end of this chapter, you will have a good under- standing of the following: |
XML serialization |
How to serialize an object into an XML format |
learn guitarphysics learnteliphonyxmlphysicsenjoylife