The ?? operator can be very useful in these scenarios. Continue reading
XmlIgnore: If you specify XmlIgnore on a field, that field will be ignored when serialized. XmlAttribute:This Specifies that the XmlSerializer must serialize the class member as an XML attribute. XmlRoot:Controls XML serialization of the attribute target as an XML root element. You can use the word XmlRoot in your code instead of the longer XmlRootAttribute.
XmlElementattribute: Indicates that a public field or property represents an XML element when the XmlSerializer serializes or deserializes the object that contains it. Set the element name and namespace of the XML element. By applying an XmlElementAttribute to an array, you instruct the XmlSerializer to serialize the array as a series of XML elements, instead of a nested set of elements. Continue reading
xsd.exe tool which gets installed with the Windows SDK into a directory something similar to:
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin
On the first run, you use
xsd.exe and you convert your sample XML into a XSD file (XML schema file):
This gives you
yourfile.xsd, which in a second step, you can convert again using
xsd.exe into a C# class:
xsd yourfile.xsd /c
This should give you a file
yourfile.cs which will contain a C# class that you can use to deserialize the XML file you’re getting – something like:
XmlSerializer serializer = new XmlSerializer(typeof(msg)); msg resultingMessage = (msg)serializer.Deserialize('yourfile.xml');
XML file that I used is Continue reading
Converting your entire class data to XML and then XML to class back is very helpful when you are doing some project . Here I am explaining how to convert your class data to XML in C# 4.0 using System.Xml.Linq.