SlideShare a Scribd company logo
1 of 15
Introduction to
Xml Serialization in C#

Presenter: Priyojit Mondal, Mindfire Solutions
Date: 20/12/2013
What are we going to learn today?









What is Xml Serialization, why to use it?
XmlSerializer Class
Serialize() method
Demo – Different types of serializations
Basic attributes to control serialization process
Xsd.exe
Some common troubleshooting
Exception handling

Presenter: Priyojit Mondal, Mindfire Solutions
What is Serialization and why do we
need it?
To persist an object and save it in a specified storage location like a
physical file or Database.
Serialization converts an object into a stream and then uses it
either to save it in a file or to send/transport over any
communication channel.

Presenter: Priyojit Mondal, Mindfire Solutions
What is XML serialization in C#.Net?


A serialization technique in which an object will be
converted/saved into xml format or stream.



To use serialization in xml we need XmlSerializer class. This class is
derived from System.Xml.Serialization.



Serialize and Deserialize are the two most important methods.

Presenter: Priyojit Mondal, Mindfire Solutions
Things to remember...


Only public objects can be serialized in XML serialization. And
hence it is also called as Shallow serialization.



Classes inherited from IEnumerable and ICollection can also be
serialized, however it serializes only collections and not public
properties.



Private or read-only properties, Methods, Indexers cannot be
serialized using this xml serialization.

Presenter: Priyojit Mondal, Mindfire Solutions
XmlSerializer Class


The central class in XML serialization




Namespace: System.Xml.Serialization
Assembly: System.Xml (in System.Xml.dll)



Serializes and deserializes objects into and from XML documents.



The XmlSerializer enables you to control how objects are encoded
into XML.
MSDN Link

Presenter: Priyojit Mondal, Mindfire Solutions
How to do XML Serialization?


XML Serialization of simple class object : Serialize the object into
XML as it is.



XML Serialization of a Class object containing many properties :
Serialize the object into XML as it is.



XML Serialization using XmlElement : Control the name of
properties using XmlElement in XML serialization. You can specify
an alternate name for properties of an object to save into XML.



XML Serialization of array of Objects : Serialize the array of objects
into XML.
Presenter: Priyojit Mondal, Mindfire Solutions
Demo

Presenter: Priyojit Mondal, Mindfire Solutions
Customization






XmlRoot
XmlElement
XmlAttribute
XmlText
XmlEnum

Presenter: Priyojit Mondal, Mindfire Solutions
XmlSerializerNamespaces Class


Contains the XML namespaces and prefixes that the XmlSerializer
uses to generate qualified names in an XML-document instance.
MSDN Link

Presenter: Priyojit Mondal, Mindfire Solutions
XML Schema Definition Tool (Xsd.exe)


The XML Schema Definition (Xsd.exe) tool generates XML schema
or common language runtime classes from XDR, XML, and XSD files,
or from classes in a runtime assembly.

Format :
xsd [file_path] /c[lasss] /o[utput]:[directory]


MSDN Link

Presenter: Priyojit Mondal, Mindfire Solutions
Troubleshooting
Case 1:
Declaring Serialization Types.
Case 2:
Working with a class with parametrized constructor.

Presenter: Priyojit Mondal, Mindfire Solutions
Exceptions from the XmlSerializer


In most cases Serialize(), Deserialize() and even the XmlSerializer
constructor throws generic System.InvalidOperationException when an
error occurs.
Message : “There was an error generating the XML document”
The Serialize() method catches all exceptions thrown in the serialization
classes, wraps them in an InvalidOperationException, and throws that up
the stack.
To get the real exception use InnerException or exception's ToString()
method.
Presenter: Priyojit Mondal, Mindfire Solutions
Question and
Answer

Presenter: Priyojit Mondal, Mindfire Solutions
Thank you

Presenter: Priyojit Mondal, Mindfire Solutions

More Related Content

What's hot

Beginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPBeginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPRick Ogden
 
Session 10 - OOP with Java - Abstract Classes and Interfaces
Session 10 - OOP with Java - Abstract Classes and InterfacesSession 10 - OOP with Java - Abstract Classes and Interfaces
Session 10 - OOP with Java - Abstract Classes and InterfacesPawanMM
 
Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Train...
Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Train...Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Train...
Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Train...Edureka!
 
PATTERNS09 - Generics in .NET and Java
PATTERNS09 - Generics in .NET and JavaPATTERNS09 - Generics in .NET and Java
PATTERNS09 - Generics in .NET and JavaMichael Heron
 
Reflection and Introspection
Reflection and IntrospectionReflection and Introspection
Reflection and Introspectionadil raja
 
Java OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - InheritanceJava OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - InheritanceOUM SAOKOSAL
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteTushar B Kute
 

What's hot (17)

Introduction to OOP(in java) BY Govind Singh
Introduction to OOP(in java)  BY Govind SinghIntroduction to OOP(in java)  BY Govind Singh
Introduction to OOP(in java) BY Govind Singh
 
core java
core javacore java
core java
 
JSpiders - Wrapper classes
JSpiders - Wrapper classesJSpiders - Wrapper classes
JSpiders - Wrapper classes
 
Java Simple Notes
Java Simple NotesJava Simple Notes
Java Simple Notes
 
Beginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPBeginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHP
 
Bab satu
Bab satuBab satu
Bab satu
 
Session 10 - OOP with Java - Abstract Classes and Interfaces
Session 10 - OOP with Java - Abstract Classes and InterfacesSession 10 - OOP with Java - Abstract Classes and Interfaces
Session 10 - OOP with Java - Abstract Classes and Interfaces
 
Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Train...
Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Train...Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Train...
Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Train...
 
C plusplus
C plusplusC plusplus
C plusplus
 
Core java
Core javaCore java
Core java
 
Inner Classes
Inner Classes Inner Classes
Inner Classes
 
PATTERNS09 - Generics in .NET and Java
PATTERNS09 - Generics in .NET and JavaPATTERNS09 - Generics in .NET and Java
PATTERNS09 - Generics in .NET and Java
 
Reflection and Introspection
Reflection and IntrospectionReflection and Introspection
Reflection and Introspection
 
Introduction to java and oop
Introduction to java and oopIntroduction to java and oop
Introduction to java and oop
 
Java OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - InheritanceJava OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - Inheritance
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
Reflection
ReflectionReflection
Reflection
 

Viewers also liked

Bengali optical character recognition system
Bengali optical character recognition systemBengali optical character recognition system
Bengali optical character recognition systemMd. Mahedi Mahfuj
 
70-483 Programming in C# Complete Study
70-483 Programming in C# Complete Study70-483 Programming in C# Complete Study
70-483 Programming in C# Complete Studydrovioph
 
Top 20 c# interview Question and answers
Top 20 c# interview Question and answersTop 20 c# interview Question and answers
Top 20 c# interview Question and answersw3asp dotnet
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining ClassesIntro C# Book
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial Jm Ramos
 
The Universal Programming Language: C#
The Universal Programming Language: C#The Universal Programming Language: C#
The Universal Programming Language: C#BizTalk360
 

Viewers also liked (14)

Serialization
SerializationSerialization
Serialization
 
Bengali optical character recognition system
Bengali optical character recognition systemBengali optical character recognition system
Bengali optical character recognition system
 
70-483 Programming in C# Complete Study
70-483 Programming in C# Complete Study70-483 Programming in C# Complete Study
70-483 Programming in C# Complete Study
 
C#2008 Black Book
C#2008 Black BookC#2008 Black Book
C#2008 Black Book
 
DSA - Lecture 04
DSA - Lecture 04DSA - Lecture 04
DSA - Lecture 04
 
Top 20 c# interview Question and answers
Top 20 c# interview Question and answersTop 20 c# interview Question and answers
Top 20 c# interview Question and answers
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
 
C# basics
 C# basics C# basics
C# basics
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
Programming in c#
Programming in c#Programming in c#
Programming in c#
 
Java basic
Java basicJava basic
Java basic
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
The Universal Programming Language: C#
The Universal Programming Language: C#The Universal Programming Language: C#
The Universal Programming Language: C#
 

Similar to It seminar-xml serialization

Working with xml data
Working with xml dataWorking with xml data
Working with xml dataaspnet123
 
Xml serialization
Xml serializationXml serialization
Xml serializationRaghu nath
 
06 xml processing-in-.net
06 xml processing-in-.net06 xml processing-in-.net
06 xml processing-in-.netglubox
 
LINQ to XML
LINQ to XMLLINQ to XML
LINQ to XMLukdpe
 
Advanced Web Programming Chapter 12
Advanced Web Programming Chapter 12Advanced Web Programming Chapter 12
Advanced Web Programming Chapter 12RohanMistry15
 
Working with XML and JSON Serializing
Working with XML and JSON SerializingWorking with XML and JSON Serializing
Working with XML and JSON Serializingssusere19c741
 
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 SivanesianMatthew McCullough
 
Xml representation oftextspecifications
Xml representation oftextspecificationsXml representation oftextspecifications
Xml representation oftextspecificationsusert098
 
Ado.net session11
Ado.net session11Ado.net session11
Ado.net session11Niit Care
 
Applied xml programming for microsoft
Applied xml programming for microsoftApplied xml programming for microsoft
Applied xml programming for microsoftRaghu nath
 
Ch23 xml processing_with_java
Ch23 xml processing_with_javaCh23 xml processing_with_java
Ch23 xml processing_with_javaardnetij
 
Applied xml programming for microsoft 3
Applied xml programming for microsoft 3Applied xml programming for microsoft 3
Applied xml programming for microsoft 3Raghu nath
 
04 sm3 xml_xp_07
04 sm3 xml_xp_0704 sm3 xml_xp_07
04 sm3 xml_xp_07Niit Care
 
04 sm3 xml_xp_08
04 sm3 xml_xp_0804 sm3 xml_xp_08
04 sm3 xml_xp_08Niit Care
 
Xml and xml processor
Xml and xml processorXml and xml processor
Xml and xml processorHimanshu Soni
 

Similar to It seminar-xml serialization (20)

The xml
The xmlThe xml
The xml
 
Working with xml data
Working with xml dataWorking with xml data
Working with xml data
 
Xml serialization
Xml serializationXml serialization
Xml serialization
 
06 xml processing-in-.net
06 xml processing-in-.net06 xml processing-in-.net
06 xml processing-in-.net
 
LINQ to XML
LINQ to XMLLINQ to XML
LINQ to XML
 
Advanced Web Programming Chapter 12
Advanced Web Programming Chapter 12Advanced Web Programming Chapter 12
Advanced Web Programming Chapter 12
 
Working with XML and JSON Serializing
Working with XML and JSON SerializingWorking with XML and JSON Serializing
Working with XML and JSON Serializing
 
Session 5
Session 5Session 5
Session 5
 
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
 
Xml representation oftextspecifications
Xml representation oftextspecificationsXml representation oftextspecifications
Xml representation oftextspecifications
 
Ado.net session11
Ado.net session11Ado.net session11
Ado.net session11
 
Applied xml programming for microsoft
Applied xml programming for microsoftApplied xml programming for microsoft
Applied xml programming for microsoft
 
XML
XMLXML
XML
 
Ch23
Ch23Ch23
Ch23
 
Ch23 xml processing_with_java
Ch23 xml processing_with_javaCh23 xml processing_with_java
Ch23 xml processing_with_java
 
Applied xml programming for microsoft 3
Applied xml programming for microsoft 3Applied xml programming for microsoft 3
Applied xml programming for microsoft 3
 
04 sm3 xml_xp_07
04 sm3 xml_xp_0704 sm3 xml_xp_07
04 sm3 xml_xp_07
 
04 sm3 xml_xp_08
04 sm3 xml_xp_0804 sm3 xml_xp_08
04 sm3 xml_xp_08
 
Dom
Dom Dom
Dom
 
Xml and xml processor
Xml and xml processorXml and xml processor
Xml and xml processor
 

Recently uploaded

"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 

Recently uploaded (20)

"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 

It seminar-xml serialization

  • 1. Introduction to Xml Serialization in C# Presenter: Priyojit Mondal, Mindfire Solutions Date: 20/12/2013
  • 2. What are we going to learn today?         What is Xml Serialization, why to use it? XmlSerializer Class Serialize() method Demo – Different types of serializations Basic attributes to control serialization process Xsd.exe Some common troubleshooting Exception handling Presenter: Priyojit Mondal, Mindfire Solutions
  • 3. What is Serialization and why do we need it? To persist an object and save it in a specified storage location like a physical file or Database. Serialization converts an object into a stream and then uses it either to save it in a file or to send/transport over any communication channel. Presenter: Priyojit Mondal, Mindfire Solutions
  • 4. What is XML serialization in C#.Net?  A serialization technique in which an object will be converted/saved into xml format or stream.  To use serialization in xml we need XmlSerializer class. This class is derived from System.Xml.Serialization.  Serialize and Deserialize are the two most important methods. Presenter: Priyojit Mondal, Mindfire Solutions
  • 5. Things to remember...  Only public objects can be serialized in XML serialization. And hence it is also called as Shallow serialization.  Classes inherited from IEnumerable and ICollection can also be serialized, however it serializes only collections and not public properties.  Private or read-only properties, Methods, Indexers cannot be serialized using this xml serialization. Presenter: Priyojit Mondal, Mindfire Solutions
  • 6. XmlSerializer Class  The central class in XML serialization   Namespace: System.Xml.Serialization Assembly: System.Xml (in System.Xml.dll)  Serializes and deserializes objects into and from XML documents.  The XmlSerializer enables you to control how objects are encoded into XML. MSDN Link Presenter: Priyojit Mondal, Mindfire Solutions
  • 7. How to do XML Serialization?  XML Serialization of simple class object : Serialize the object into XML as it is.  XML Serialization of a Class object containing many properties : Serialize the object into XML as it is.  XML Serialization using XmlElement : Control the name of properties using XmlElement in XML serialization. You can specify an alternate name for properties of an object to save into XML.  XML Serialization of array of Objects : Serialize the array of objects into XML. Presenter: Priyojit Mondal, Mindfire Solutions
  • 8. Demo Presenter: Priyojit Mondal, Mindfire Solutions
  • 10. XmlSerializerNamespaces Class  Contains the XML namespaces and prefixes that the XmlSerializer uses to generate qualified names in an XML-document instance. MSDN Link Presenter: Priyojit Mondal, Mindfire Solutions
  • 11. XML Schema Definition Tool (Xsd.exe)  The XML Schema Definition (Xsd.exe) tool generates XML schema or common language runtime classes from XDR, XML, and XSD files, or from classes in a runtime assembly. Format : xsd [file_path] /c[lasss] /o[utput]:[directory]  MSDN Link Presenter: Priyojit Mondal, Mindfire Solutions
  • 12. Troubleshooting Case 1: Declaring Serialization Types. Case 2: Working with a class with parametrized constructor. Presenter: Priyojit Mondal, Mindfire Solutions
  • 13. Exceptions from the XmlSerializer  In most cases Serialize(), Deserialize() and even the XmlSerializer constructor throws generic System.InvalidOperationException when an error occurs. Message : “There was an error generating the XML document” The Serialize() method catches all exceptions thrown in the serialization classes, wraps them in an InvalidOperationException, and throws that up the stack. To get the real exception use InnerException or exception's ToString() method. Presenter: Priyojit Mondal, Mindfire Solutions
  • 14. Question and Answer Presenter: Priyojit Mondal, Mindfire Solutions
  • 15. Thank you Presenter: Priyojit Mondal, Mindfire Solutions