How to deserialize XML in C #

2

I am making an addendum for an XML, I go through the file with a split but I have heard that good practice would be to deserialize. How do I go through the xml and transform it into an object to manipulate it?

    
asked by Isaac Ríos 18.10.2016 в 19:17
source

1 answer

3

Deserialization does not need to go through anything, you just have to be able to map the xml with a class that you define.

Having the xml you can get the class that maps with this using tools such as

link

or you can use Visual Studio to get the class that you get from the xml

Generate Class From JSON or XML in Visual Studio

The idea is that later you use

How to serialize an object

How to deserialize an object

XmlSerializer mySerializer = new XmlSerializer(typeof(MySerializableClass));

FileStream myFileStream = new FileStream("myFileName.xml", FileMode.Open);

MySerializableClass myObject = (MySerializableClass)mySerializer.Deserialize(myFileStream);

where it says MySerializableClass you must indicate the class that you get from the xml structure

    
answered by 18.10.2016 / 19:38
source