SlideShare une entreprise Scribd logo
1  sur  9
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.
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.

Contenu connexe

Tendances

Tendances (20)

Structured query language(sql)ppt
Structured query language(sql)pptStructured query language(sql)ppt
Structured query language(sql)ppt
 
Oracle Database Sequence
Oracle Database SequenceOracle Database Sequence
Oracle Database Sequence
 
SQLite database in android
SQLite database in androidSQLite database in android
SQLite database in android
 
Uml
UmlUml
Uml
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
 
Advanced sql
Advanced sqlAdvanced sql
Advanced sql
 
Collections Api - Java
Collections Api - JavaCollections Api - Java
Collections Api - Java
 
Java RMI
Java RMIJava RMI
Java RMI
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Serialization in .NET
Serialization in .NETSerialization in .NET
Serialization in .NET
 
Type constructor
Type constructorType constructor
Type constructor
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Java web application development
Java web application developmentJava web application development
Java web application development
 
MySQL
MySQLMySQL
MySQL
 
C# Framework class library
C# Framework class libraryC# Framework class library
C# Framework class library
 
Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)
 
ETL big data with apache hadoop
ETL big data with apache hadoopETL big data with apache hadoop
ETL big data with apache hadoop
 
5. stored procedure and functions
5. stored procedure and functions5. stored procedure and functions
5. stored procedure and functions
 
Object modeling
Object modelingObject modeling
Object modeling
 

Similaire à Xml serialization

Applied xml programming for microsoft
Applied xml programming for microsoftApplied xml programming for microsoft
Applied xml programming for microsoft
Raghu nath
 
XStream Quick Start
XStream Quick StartXStream Quick Start
XStream Quick Start
Guo Albert
 
Applied xml programming for microsoft 2
Applied xml programming for microsoft  2Applied xml programming for microsoft  2
Applied xml programming for microsoft 2
Raghu nath
 
Ado.net xml data serialization
Ado.net xml data serializationAdo.net xml data serialization
Ado.net xml data serialization
Raghu nath
 
Working with xml data
Working with xml dataWorking with xml data
Working with xml data
aspnet123
 

Similaire à Xml serialization (20)

Applied xml programming for microsoft
Applied xml programming for microsoftApplied xml programming for microsoft
Applied xml programming for microsoft
 
XStream Quick Start
XStream Quick StartXStream Quick Start
XStream Quick Start
 
Xml writers
Xml writersXml writers
Xml writers
 
Er2000
Er2000Er2000
Er2000
 
Enhanced xml validation using srml01
Enhanced xml validation using srml01Enhanced xml validation using srml01
Enhanced xml validation using srml01
 
Unit 2.3
Unit 2.3Unit 2.3
Unit 2.3
 
Linq to xml
Linq to xmlLinq to xml
Linq to xml
 
Jaxp Xmltutorial 11 200108
Jaxp Xmltutorial 11 200108Jaxp Xmltutorial 11 200108
Jaxp Xmltutorial 11 200108
 
XML
XMLXML
XML
 
Unit 2.3
Unit 2.3Unit 2.3
Unit 2.3
 
Ch23
Ch23Ch23
Ch23
 
Ch23 xml processing_with_java
Ch23 xml processing_with_javaCh23 xml processing_with_java
Ch23 xml processing_with_java
 
LINQ to XML
LINQ to XMLLINQ to XML
LINQ to XML
 
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
 
DOSUG XML Beans overview by Om Sivanesian
DOSUG XML Beans overview by Om SivanesianDOSUG XML Beans overview by Om Sivanesian
DOSUG XML Beans overview by Om Sivanesian
 
Applied xml programming for microsoft 2
Applied xml programming for microsoft  2Applied xml programming for microsoft  2
Applied xml programming for microsoft 2
 
The xml
The xmlThe xml
The xml
 
Ado.net xml data serialization
Ado.net xml data serializationAdo.net xml data serialization
Ado.net xml data serialization
 
Working with xml data
Working with xml dataWorking with xml data
Working with xml data
 
Sql Summit Clr, Service Broker And Xml
Sql Summit   Clr, Service Broker And XmlSql Summit   Clr, Service Broker And Xml
Sql Summit Clr, Service Broker And Xml
 

Plus de Raghu nath

Ftp (file transfer protocol)
Ftp (file transfer protocol)Ftp (file transfer protocol)
Ftp (file transfer protocol)
Raghu nath
 
Javascript part1
Javascript part1Javascript part1
Javascript part1
Raghu nath
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
Raghu nath
 
Selection sort
Selection sortSelection sort
Selection sort
Raghu nath
 
Binary search
Binary search Binary search
Binary search
Raghu nath
 
JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)
Raghu nath
 
Stemming algorithms
Stemming algorithmsStemming algorithms
Stemming algorithms
Raghu nath
 
Step by step guide to install dhcp role
Step by step guide to install dhcp roleStep by step guide to install dhcp role
Step by step guide to install dhcp role
Raghu nath
 
Network essentials chapter 4
Network essentials  chapter 4Network essentials  chapter 4
Network essentials chapter 4
Raghu nath
 
Network essentials chapter 3
Network essentials  chapter 3Network essentials  chapter 3
Network essentials chapter 3
Raghu nath
 
Network essentials chapter 2
Network essentials  chapter 2Network essentials  chapter 2
Network essentials chapter 2
Raghu nath
 
Network essentials - chapter 1
Network essentials - chapter 1Network essentials - chapter 1
Network essentials - chapter 1
Raghu nath
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2
Raghu nath
 
python chapter 1
python chapter 1python chapter 1
python chapter 1
Raghu nath
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell Scripting
Raghu nath
 

Plus de Raghu nath (20)

Mongo db
Mongo dbMongo db
Mongo db
 
Ftp (file transfer protocol)
Ftp (file transfer protocol)Ftp (file transfer protocol)
Ftp (file transfer protocol)
 
MS WORD 2013
MS WORD 2013MS WORD 2013
MS WORD 2013
 
Msword
MswordMsword
Msword
 
Ms word
Ms wordMs word
Ms word
 
Javascript part1
Javascript part1Javascript part1
Javascript part1
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Selection sort
Selection sortSelection sort
Selection sort
 
Binary search
Binary search Binary search
Binary search
 
JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)
 
Stemming algorithms
Stemming algorithmsStemming algorithms
Stemming algorithms
 
Step by step guide to install dhcp role
Step by step guide to install dhcp roleStep by step guide to install dhcp role
Step by step guide to install dhcp role
 
Network essentials chapter 4
Network essentials  chapter 4Network essentials  chapter 4
Network essentials chapter 4
 
Network essentials chapter 3
Network essentials  chapter 3Network essentials  chapter 3
Network essentials chapter 3
 
Network essentials chapter 2
Network essentials  chapter 2Network essentials  chapter 2
Network essentials chapter 2
 
Network essentials - chapter 1
Network essentials - chapter 1Network essentials - chapter 1
Network essentials - chapter 1
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2
 
python chapter 1
python chapter 1python chapter 1
python chapter 1
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell Scripting
 
Perl
PerlPerl
Perl
 

Dernier

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Dernier (20)

Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

Xml serialization

  • 1.
  • 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.
  • 8.
  • 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.