So you want to compare two XML strings together to see if they are equal. Obviously, it would be easy to just compare the two strings using a regular string equality comparison and call it a day. However, what if the XML strings looked like the following:
All of the nodes, attributes and values are the same, but the formatting is way off. Obviously, a string equality comparison between these two would return false. Is there anything that can be done about this? Not to fear, .NET provides a pretty simple solution. Continue reading →
Serialization is a process of converting an object into a stream of data, to easily transfer over the network or to save to disk. So, using this concept of serialization, we can serialize any object to XML string. Here is a person class that we can serialize.
Here is the code that takes the person object into string of xml format.
Using Serialization in .NET is provided by the System.Runtim.Serialization name space.
Once you have the XML string, now you can save it to disk, store it into database, or transfer over the network. Here is the deserialization method that takes serialized string of XML into the person object.