SlideShare a Scribd company logo
Xml serialization
Serialization is the run-time process that converts an object, or a graph of objects, to a linear sequence of bytes.
You can then use the resultant block of memory either for storage or for transmission over the network on top of a
particular protocol. In the Microsoft .NET Framework, object serialization can have three different output forms:
binary, Simple Object Access Protocol (SOAP), and XML.
Run-time object serialization (for example, binary and SOAP) and XML serialization are significantly different
technologies with different implementations and, more important, different goals. Nevertheless, both forms of
serialization do just one key thing: they save the contents and the state of living objects out to memory, and from
there to any other storage media. Run-time serialization is governed by .NET Framework formatter
objects. XML serialization takes place under the aegis of the XmlSerializer class
The XML serialization process converts the public interface of an object to a particular XML schema. Such a mechanism is
widely used throughout the .NET Framework as a way to save the state of an object into a stream or a memory buffer.
The Object Serialization Process
In the .NET Framework, object serialization is offered through the classes in the System.Runtime.Serialization namespace.
These classes provide type fidelity and support deserialization. As you probably know, the deserialization process is the
reverse of serialization. Deserialization takes in stored information and recreates objects from that information.
The SOAP Formatter
To use the SOAP formatter, you must reference a distinct assembly— System.Runtime.Serialization.Formatters.Soap. You
add this separate assembly through the Add Reference dialog box or manually on the compiler's command line
through the /reference switch. In addition to linking the assembly to the project, you still have to import the namespace
with the same name as the assembly, as shown here:
From SOAP to XML Serialization
A second, very special type of .NET Framework serialization is XML serialization. Compared to ordinary .NET Framework
object serialization, XML serialization is so different that it shouldn't even be considered another type of formatter. It is
similar to SOAP and binary formatters because it also persists and restores the object's state, but when you examine the
way each serializer works, you see many significant differences.
XML serialization is handled by using the XmlSerializer class, which also enables you to control how objects are
encoded into elements of an XML schema. In addition to differences in goals and implementation details, the strongest
difference between runtime and XML serialization is in the level of type fidelity they provide.
The primary goal of XML serialization is making another application, possibly an application running on a different
platform, effectively able to consume any stored data. Let's recap the key differences between run-time and XML
serialization:
Persisted properties Run-time serialization takes into account any properties, regardless of the scope a property has in
the context of the class. XML serialization, on the other hand, avoids private, protected, and read-only properties; does
not handle circular references; and works only with public classes. In addition, if one property is set to null in the
particular instance being serialized, the XML serializer just ignores the property. The XML serializer never includes type
information. .. Object identity Run-time serialization maintains information about the original class name, namespace,
and assembly. All this information—the object's identity—is irreversibly lost with XML serialization. .. Control of the
output Run-time serialization lets you indicate the data to serialize by adding values to a cargo collection. You can't
control how these values are actually written, however. The schema of the persisted data is fixed and hard-coded in the
formatter. In this respect, the XML serializer is much more flexible. The XML serializer lets you specify namespaces, the
name of the XML element that will contain a particular property, and even whether a given property should be
rendered as an attribute, text, or an element.
The XML Serializer
The central element in the XML serialization architecture is the XmlSerializer class,which belongs to the
System.Xml.Serialization namespace. The XML serialization process is articulated in the following steps:
1. The serializer generates an XSD schema for the target class that includes all the public properties and fields.
2. Using this XSD schema, the serializer generates a C# source file with a made-to-measure reader and writer class. The
source file is compiled into a temporary assembly.
The Serialize and Deserialize methods are simply higher level interfaces for those writer and reader classes. This list does
not cover all the features of XML serialization, but it certainly focuses on the key aspects. Let's look more closely at these
key aspects before we move on to more advanced issues such as customizing the XSD schema being generated and
hooking up the deserialization process.
The XML serializer works on top of a particular type—the target class. While deserializing, the deserializer engine
attempts to fit incoming data into the properties of the target class, taking into careful account any attributes set for
the various properties. What happens if the source and the destination follow incompatible schemas? This
might seem a rather odd situation—how could you deserialize data that you haven't previously serialized?—but in
practice it exemplifies the real goal of XML serialization. Beyond any technological and implementation details, XML
serialization is simply a way to automatically instantiate classes from XML data.
Xml serialization
The XML serializer is a double-edged sword. On one hand, it lets you serialize and deserialize even complex
.NET Framework classes to and from XML with very few lines of code. To accomplish this, the serializer
needs to create an assembly on the fly. If you don't use a global instance of the serializer for each type, you
can easily add hundreds of milliseconds of overhead to each call—definitely not a pleasant prospect
On the other hand, appropriately used, XML serialization produces more compact code than run-time
SOAP serialization. If you add type information, and SOAP type information in particular, the ratio changes,
however. The moral of this story is don't ever mix XML and SOAP—use only the process you need.
Serialization is one of the new frontiers of XML. It is not clear yet whether today's SOAP, extensions to
SOAP, or a brand-new dialect will become the universal platform for describing objects. Currently, XML
serialization is a hybrid, incomplete, technology. Originally designed as a tool running underneath the .NET
Framework implementation of Web services, XML serialization entered prime time a bit too early, or if not
too early, certainly not optimized.

More Related Content

What's hot (20)

PPTX
AWS Re:Invent - High Availability Architecture at Netflix
Adrian Cockcroft
 
PPTX
Asynchronous programming in C#
Bohdan Pashkovskyi
 
PPT
Selenium
Ruturaj Doshi
 
PDF
Amazon AWS | What is Amazon AWS | AWS Tutorial | AWS Training | Edureka
Edureka!
 
PDF
Data platform data pipeline(Airflow, Kubernetes)
창언 정
 
PDF
효율적인 빅데이터 분석 및 처리를 위한 Glue, EMR 활용 - 김태현 솔루션즈 아키텍트, AWS :: AWS Summit Seoul 2019
Amazon Web Services Korea
 
PDF
Aws 101 A walk-through the aws cloud (2013)
Martin Yan
 
PDF
Amazon EventBridge
Dhaval Nagar
 
PPT
A complete guide to azure storage
Himanshu Sahu
 
PPTX
The Stream Processor as a Database Apache Flink
DataWorks Summit/Hadoop Summit
 
PPTX
Cloud Formation
TO THE NEW | Technology
 
PPT
Intro to Amazon S3
Yu Lun Teo
 
PPTX
Apache zookeeper 101
Quach Tung
 
PPTX
Ansible를 통한 컨테이너 환경 자동화
Opennaru, inc.
 
PPTX
webworkers
Asanka Indrajith
 
PDF
Reactjs Basics
Hamid Ghorbani
 
PDF
Streaming Event Time Partitioning with Apache Flink and Apache Iceberg - Juli...
Flink Forward
 
ODP
Apache Spark Internals
Knoldus Inc.
 
PDF
Amazon EKS 그리고 Service Mesh (김세호 솔루션즈 아키텍트, AWS) :: Gaming on AWS 2018
Amazon Web Services Korea
 
PPTX
MongoDB and Azure Databricks
MongoDB
 
AWS Re:Invent - High Availability Architecture at Netflix
Adrian Cockcroft
 
Asynchronous programming in C#
Bohdan Pashkovskyi
 
Selenium
Ruturaj Doshi
 
Amazon AWS | What is Amazon AWS | AWS Tutorial | AWS Training | Edureka
Edureka!
 
Data platform data pipeline(Airflow, Kubernetes)
창언 정
 
효율적인 빅데이터 분석 및 처리를 위한 Glue, EMR 활용 - 김태현 솔루션즈 아키텍트, AWS :: AWS Summit Seoul 2019
Amazon Web Services Korea
 
Aws 101 A walk-through the aws cloud (2013)
Martin Yan
 
Amazon EventBridge
Dhaval Nagar
 
A complete guide to azure storage
Himanshu Sahu
 
The Stream Processor as a Database Apache Flink
DataWorks Summit/Hadoop Summit
 
Cloud Formation
TO THE NEW | Technology
 
Intro to Amazon S3
Yu Lun Teo
 
Apache zookeeper 101
Quach Tung
 
Ansible를 통한 컨테이너 환경 자동화
Opennaru, inc.
 
webworkers
Asanka Indrajith
 
Reactjs Basics
Hamid Ghorbani
 
Streaming Event Time Partitioning with Apache Flink and Apache Iceberg - Juli...
Flink Forward
 
Apache Spark Internals
Knoldus Inc.
 
Amazon EKS 그리고 Service Mesh (김세호 솔루션즈 아키텍트, AWS) :: Gaming on AWS 2018
Amazon Web Services Korea
 
MongoDB and Azure Databricks
MongoDB
 

Similar to Xml serialization (20)

PPTX
Applied xml programming for microsoft
Raghu nath
 
PPT
XStream Quick Start
Guo Albert
 
DOC
Serialization in .NET
Abhi Arya
 
PPTX
Xml writers
Raghu nath
 
PDF
Er2000
LiquidHub
 
PDF
Enhanced xml validation using srml01
IJwest
 
DOCX
Unit 2.3
Abhishek Kesharwani
 
PPTX
Linq to xml
Mickey
 
PDF
Jaxp Xmltutorial 11 200108
nit Allahabad
 
PDF
Unit 2.3
Abhishek Kesharwani
 
PDF
Ch23
preetamju
 
PDF
Ch23 xml processing_with_java
ardnetij
 
PPT
LINQ to XML
ukdpe
 
PPT
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
Marco Gralike
 
PPT
DOSUG XML Beans overview by Om Sivanesian
Matthew McCullough
 
PPTX
Applied xml programming for microsoft 2
Raghu nath
 
PPTX
The xml
Raghu nath
 
PPTX
Ado.net xml data serialization
Raghu nath
 
PPTX
Working with xml data
aspnet123
 
Applied xml programming for microsoft
Raghu nath
 
XStream Quick Start
Guo Albert
 
Serialization in .NET
Abhi Arya
 
Xml writers
Raghu nath
 
Er2000
LiquidHub
 
Enhanced xml validation using srml01
IJwest
 
Linq to xml
Mickey
 
Jaxp Xmltutorial 11 200108
nit Allahabad
 
Ch23
preetamju
 
Ch23 xml processing_with_java
ardnetij
 
LINQ to XML
ukdpe
 
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
Marco Gralike
 
DOSUG XML Beans overview by Om Sivanesian
Matthew McCullough
 
Applied xml programming for microsoft 2
Raghu nath
 
The xml
Raghu nath
 
Ado.net xml data serialization
Raghu nath
 
Working with xml data
aspnet123
 
Ad

More from Raghu nath (20)

PPTX
Mongo db
Raghu nath
 
PDF
Ftp (file transfer protocol)
Raghu nath
 
PDF
MS WORD 2013
Raghu nath
 
PDF
Msword
Raghu nath
 
PDF
Ms word
Raghu nath
 
PDF
Javascript part1
Raghu nath
 
PDF
Regular expressions
Raghu nath
 
PDF
Selection sort
Raghu nath
 
PPTX
Binary search
Raghu nath
 
PPTX
JSON(JavaScript Object Notation)
Raghu nath
 
PDF
Stemming algorithms
Raghu nath
 
PPTX
Step by step guide to install dhcp role
Raghu nath
 
PPTX
Network essentials chapter 4
Raghu nath
 
PPTX
Network essentials chapter 3
Raghu nath
 
PPTX
Network essentials chapter 2
Raghu nath
 
PPTX
Network essentials - chapter 1
Raghu nath
 
PPTX
Python chapter 2
Raghu nath
 
PPTX
python chapter 1
Raghu nath
 
PPTX
Linux Shell Scripting
Raghu nath
 
PPTX
Perl
Raghu nath
 
Mongo db
Raghu nath
 
Ftp (file transfer protocol)
Raghu nath
 
MS WORD 2013
Raghu nath
 
Msword
Raghu nath
 
Ms word
Raghu nath
 
Javascript part1
Raghu nath
 
Regular expressions
Raghu nath
 
Selection sort
Raghu nath
 
Binary search
Raghu nath
 
JSON(JavaScript Object Notation)
Raghu nath
 
Stemming algorithms
Raghu nath
 
Step by step guide to install dhcp role
Raghu nath
 
Network essentials chapter 4
Raghu nath
 
Network essentials chapter 3
Raghu nath
 
Network essentials chapter 2
Raghu nath
 
Network essentials - chapter 1
Raghu nath
 
Python chapter 2
Raghu nath
 
python chapter 1
Raghu nath
 
Linux Shell Scripting
Raghu nath
 
Ad

Recently uploaded (20)

PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 

Xml serialization

  • 2. Serialization is the run-time process that converts an object, or a graph of objects, to a linear sequence of bytes. You can then use the resultant block of memory either for storage or for transmission over the network on top of a particular protocol. In the Microsoft .NET Framework, object serialization can have three different output forms: binary, Simple Object Access Protocol (SOAP), and XML. Run-time object serialization (for example, binary and SOAP) and XML serialization are significantly different technologies with different implementations and, more important, different goals. Nevertheless, both forms of serialization do just one key thing: they save the contents and the state of living objects out to memory, and from there to any other storage media. Run-time serialization is governed by .NET Framework formatter objects. XML serialization takes place under the aegis of the XmlSerializer class
  • 3. The XML serialization process converts the public interface of an object to a particular XML schema. Such a mechanism is widely used throughout the .NET Framework as a way to save the state of an object into a stream or a memory buffer. The Object Serialization Process In the .NET Framework, object serialization is offered through the classes in the System.Runtime.Serialization namespace. These classes provide type fidelity and support deserialization. As you probably know, the deserialization process is the reverse of serialization. Deserialization takes in stored information and recreates objects from that information. The SOAP Formatter To use the SOAP formatter, you must reference a distinct assembly— System.Runtime.Serialization.Formatters.Soap. You add this separate assembly through the Add Reference dialog box or manually on the compiler's command line through the /reference switch. In addition to linking the assembly to the project, you still have to import the namespace with the same name as the assembly, as shown here:
  • 4. From SOAP to XML Serialization A second, very special type of .NET Framework serialization is XML serialization. Compared to ordinary .NET Framework object serialization, XML serialization is so different that it shouldn't even be considered another type of formatter. It is similar to SOAP and binary formatters because it also persists and restores the object's state, but when you examine the way each serializer works, you see many significant differences. XML serialization is handled by using the XmlSerializer class, which also enables you to control how objects are encoded into elements of an XML schema. In addition to differences in goals and implementation details, the strongest difference between runtime and XML serialization is in the level of type fidelity they provide.
  • 5. The primary goal of XML serialization is making another application, possibly an application running on a different platform, effectively able to consume any stored data. Let's recap the key differences between run-time and XML serialization: Persisted properties Run-time serialization takes into account any properties, regardless of the scope a property has in the context of the class. XML serialization, on the other hand, avoids private, protected, and read-only properties; does not handle circular references; and works only with public classes. In addition, if one property is set to null in the particular instance being serialized, the XML serializer just ignores the property. The XML serializer never includes type information. .. Object identity Run-time serialization maintains information about the original class name, namespace, and assembly. All this information—the object's identity—is irreversibly lost with XML serialization. .. Control of the output Run-time serialization lets you indicate the data to serialize by adding values to a cargo collection. You can't control how these values are actually written, however. The schema of the persisted data is fixed and hard-coded in the formatter. In this respect, the XML serializer is much more flexible. The XML serializer lets you specify namespaces, the name of the XML element that will contain a particular property, and even whether a given property should be rendered as an attribute, text, or an element.
  • 6. The XML Serializer The central element in the XML serialization architecture is the XmlSerializer class,which belongs to the System.Xml.Serialization namespace. The XML serialization process is articulated in the following steps: 1. The serializer generates an XSD schema for the target class that includes all the public properties and fields. 2. Using this XSD schema, the serializer generates a C# source file with a made-to-measure reader and writer class. The source file is compiled into a temporary assembly. The Serialize and Deserialize methods are simply higher level interfaces for those writer and reader classes. This list does not cover all the features of XML serialization, but it certainly focuses on the key aspects. Let's look more closely at these key aspects before we move on to more advanced issues such as customizing the XSD schema being generated and hooking up the deserialization process.
  • 7. The XML serializer works on top of a particular type—the target class. While deserializing, the deserializer engine attempts to fit incoming data into the properties of the target class, taking into careful account any attributes set for the various properties. What happens if the source and the destination follow incompatible schemas? This might seem a rather odd situation—how could you deserialize data that you haven't previously serialized?—but in practice it exemplifies the real goal of XML serialization. Beyond any technological and implementation details, XML serialization is simply a way to automatically instantiate classes from XML data.
  • 9. The XML serializer is a double-edged sword. On one hand, it lets you serialize and deserialize even complex .NET Framework classes to and from XML with very few lines of code. To accomplish this, the serializer needs to create an assembly on the fly. If you don't use a global instance of the serializer for each type, you can easily add hundreds of milliseconds of overhead to each call—definitely not a pleasant prospect On the other hand, appropriately used, XML serialization produces more compact code than run-time SOAP serialization. If you add type information, and SOAP type information in particular, the ratio changes, however. The moral of this story is don't ever mix XML and SOAP—use only the process you need. Serialization is one of the new frontiers of XML. It is not clear yet whether today's SOAP, extensions to SOAP, or a brand-new dialect will become the universal platform for describing objects. Currently, XML serialization is a hybrid, incomplete, technology. Originally designed as a tool running underneath the .NET Framework implementation of Web services, XML serialization entered prime time a bit too early, or if not too early, certainly not optimized.