Understanding XML Serialization in .NET Framework
XML Serialization can enable you to convert any common language runtime objects into XML documents or streams and vise versa. The XML Serialization makes it possible to convert XML documents into such a meaningful format that all programming languages can process the converted documents without any difficulty. It is also possible for you to transfer or transport the objects serialized to XML in an open standards compliant and platform agnostic manner.
The XML Serialization process in .NET Framework can make you to serialize objects into XML format that can conform to the specific XML Schema Definition (XSD) schema or even to the serialization format that has been defined in the SOAP specification. During any XML Serialization only the fields of objects that hold public properties alone are serialized. You must also be aware that during the XML Serialization it may not be possible all the time to preserve the type fidelity.
For instance, the Book object in a Library namespace cannot be deserialized into a same type of object and this indicates that there is no necessity for the target machine to have the same type of object and hence you can transfer or transport objects that has been serialized using XML Serialization in one machine to another machine even in the absence of original type in the target machine.
The XML documents that have been converted to objects by XML Serialization are strongly typed. A schema that has been written in XSD (XML Schema Definition) Language will be able to associate the information on data type with that of the attributes and elements of an XML document. The XML Serializer using the information of the data type in the schema converts the XML documents into strongly typed classes.
Further, the XML Serializer class can also be made for deserializing and serializing objects and with the help of the XML Schema Definition Tool you will be able to create classes meant for serialization. While serializing an object as XML with the XMLSerializer class, you can have full control over the process and while creating the XML Web Service, you have to apply all the attributes that control serialization to classes and members, so as to ensure that the envisaged XML output conforms to a particular schema always.
using the XML Serializer, you can have a control over the need of a field or property
to be encoded either as an attribute or an element. Further, while using the XML
Serializer for specifying the name of an attribute or an element you can also
additionally specify the XML namespace in the event of a field or property name