Serialize XML C# | Deserialize XML C# [XML Parser C#] - XML to Object C# - List to XML C#

preview_player
Показать описание
In this video, I'll walk you through serialization (Serialize XML C#) of objects or a list of objects in XML format and deserialization (Deserialize XML C#) of an XML file or XML String back to an object or a list of objects.

Serialization is a process by which an object's state is transformed in some serial data format, such as XML or binary format.
Deserialization, on the other hand, is used to convert the byte of data, such as XML or binary data, to object type.

Serialization is the process of converting an object into a form that can be readily transported. For example, you can serialize an object and transport it over the Internet using HTTP between a client and a server.
On the other end, deserialization reconstructs the object from the stream. XML serialization results in strongly typed classes with public properties and fields that are converted to a serial format (in this case, XML) for storage or transport.

The XmlSerializer object helps us to serialize and deserialize an objects or a list of objects into and from XML documents. Also, the XmlSerializer enables us to control how objects are encoded into XML.

Topics covered in this video:
1 - Serializing XML String/XML File from a C# Object [C# XML Serialize / XML Serialize C#]
2 - Deserializing a C# Object from a XML String/XML File [C# XML Deserialize / XML Deserialize C#]
3 - Serializing XML String/XML File from a list of objects [List to XML C#]
4 - Deserializing list of objects from a XML String/XML File [XML to List C#]
5 - Attributes that can be used for XML Serialization and Deserialization

Source Code:

Attributes can be used to control the XML serialization of an object or to create an alternate XML stream from the same set of classes.
Using the XmlSerializer, you can generate more than one XML stream with the same set of classes. You might want to do this because two different XML Web services require the same basic information, with only slight differences.

XmlRoot Attribute:
The XmlRootAttribute allows you to set an alternate name for the root of the XML element, the element namespace. By default, the XmlSerializer uses the class name. The attribute also allows you to set the XML namespace for the element.

XmlElement Attribute:
Indicates that a public field or property represents an XML element when the XmlSerializer serializes or deserializes the object that contains it.

XmlIgnore Attribute:
There might be situations when a public property or field does not need to be serialized. For example, a field or property could be used to contain metadata. In such cases, apply the XmlIgnoreAttribute to the field or property and the XmlSerializer will skip over it.

XmlAttribute Attribute:
The XmlAttribute instructs the XmlSerializer to serialize the Name field as an XML attribute instead of an XML element (the default behavior).

Video Chapters:
0:00 - Intro
2:51 - Project Setup
3:40 - Serialize to XML String & File
11:14 - XML Serializer Attributes
15:41 - Serialize a List of Objects
20:11 - Deserialize from XML Files
25:17 - Deserialize from XML String

You can reach us at Social Media:

#codingdroplets #csharp #csharpxml
Рекомендации по теме
Комментарии
Автор

One of the best tutorials I've ever came across. Thank you.

RajiurRahman
Автор

Excellent explanation! Clearly noted down each and every point and this video is pure gold for beginners like me. Please don't stop making videos :)

hemanthreddyveluri
Автор

I watched this over and over. Thank you

sergioalvarado
Автор

Congrats and thank you!!! your video is pretty clear and quite useful !

gabymontesvielma
Автор

very very VERY helpful! thanks a lot for sharing🤗!

irenedonati
Автор

I m from Brazil, very good, Thank you!

rafaeltabarinbernardes
Автор

You are amazing Man, Well done, thanks a lot

codercoder
Автор

That helped me a lot!!!
Thanks for your video!!

AdrDo
Автор

How would one be able to read/get a specific property from the the xml file and use the property as a parameter in a separate method?

habibi
Автор

Very Very Very Very Good Good Good Good !

adamzhang
Автор

Hey, Thanks for the video!
Is it possible to add another member of a list from user input to the xml file? When I tried it, it deleted the previous members.

Bazs
Автор

Great video! Extremely well done!

Do you have a video on how to serialize/deserialize an XML file that has many child and sub-child elements?

TheOldMaritimer
Автор

Hi how do you serialize data that has many sub xml tags

dilip_
Автор

Thank you so much loved your video
Yet I couldnt solve one problem while deserializing my xml file <Products xmlns=''> was not expected. i keep getting this error i did some research but couldnt f'x 't do u have any idea of fixxing this by any change thnk you so much

h.ferruhkaleli
Автор

Are you from Zimbabwe? Your English is impeccable but my friend is from zim and you have a very similar accent :)

Nickgowans
welcome to shbcf.ru