Mark Wilson I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :
03/19/2008
Times viewed :
2045
XmlSerializer .NET Tutorial
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. 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 easily 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.
Unfortunately the Microsoft platform lacked an easy, integrated
way to transform objects in a program into XML documents and XML documents into
objects. When it came to building XML-driven applications, developers could
choose to bypass all type-safety and pass XML around in their systems, but in
order to build a clean, object oriented architecture they had to invest time
and resources into adding functionality to every class to save itself to XML.
This functionality is referred to as serialization. The reverse operation, when
an object is re-created from its serialized representation is called
deserialization or XML data bindng. Figure 1 illustrates this process.
Figure 9.1:
Xml serialization allows transforming objects to XML and vice versa. Object
state is persisted to XML documents, which are well suited for storage or
transmission. The XML documents can then be deserialized back into objects.
We will learn about using
the .NET framework to serialize objects to an XML-based representation and then
deserializing the XML back into objects. You will learn how to develop classes
so their XML representation will map to a given XML format. This is a common
problem in applications exchanging data through an XML-based format and the
.NET Framework provides a powerful solution in the System.Xml.Serialization namespace.
Later in this book we will concentrate on
XML Serialization in the context of more distributed applications where we
communicate through an XML-based remote procedure call (RPC) protocol named
SOAP.