Serialization of the data object to XML string and deserialize

In order to serialize data object you need to connect the Assembly ICSSoft.STORMNET.Tools. To convert the XML class is designed ToolXML this Assembly, which supports two methods of serialization, described later.

Serialization of data objects in a special way

Special methods ToolXML for DataObject:

  • DataObject2XMLDocument is to convert the data object to XmlDocument,
  • XMLDocument2DataObject - inverse transformation.

There is a possibility when you serialize a data object to serialize and also master, not just its type primary key by passing the appropriate flags when calling the method. Methods DataObject2XMLDocument and XMLDocument2DataObject described in article.

Example of serialization and deserialization of the data object.

DataObject sdo = new SimpleDataObject();
((SimpleDataObject)sdo).Name="Simple data object name";
((SimpleDataObject)sdo).IntAttr = 991;

XmlDocument xmldoc = ToolXML.DataObject2XMLDocument(ref sdo);

Console.WriteLine("SimpleDataObject in XML:");
Console.WriteLine(xmldoc.InnerXml);

DataObject sdorestoredfromxml = new SimpleDataObject();
ToolXML.XMLDocument2DataObject(ref sdorestoredfromxml, xmldoc);

Console.WriteLine("Restored SimpleDataObject Name:");
Console.WriteLine( ((SimpleDataObject)sdorestoredfromxml).Name );

Console.Read();

##-based Serialization SOAP

ToolXML supports a method for the SOAP serialization. This option is less attractive because the output contains many redundant information and data object must be marked Serializable

Example of serialization and deserialization of the data object.

DataObjectWithKeyGuid dataObjectWithKeyGuid = new DataObjectWithKeyGuid();
KeyGuid g = Guid.NewGuid();
dataObjectWithKeyGuid.LinkToMaster = g;
Console.WriteLine("Recorded Guid " + dataObjectWithKeyGuid.LinkToMaster);
var serializedObj = ToolXML.ObjectToString(dataObjectWithKeyGuid);

DataObjectWithKeyGuid dObjFromXML = (DataObjectWithKeyGuid)ToolXML.ObjectFromString(serializedObj);