This sample demonstrates the serialization and de-serialization of schema information using XML serialization.
Features:
Serialization and de-serialization of the grid's schema information using XML serialization
Saving the state of an object by converting it into a stream of bytes
Reversing serialization, also called de-serialization
Interactive Features:
The methods to achieve this are WriteXmlSchema and CreateFromXml of the grid engine.
The code to load the schema uses a combination of XmlReader and CreateFromXml or ApplyXmlSchema.
Here is the code used to save the schema with XmlTextWriter
and WriteXmlSchema.
FileDialog dlg = new SaveFileDialog(); dlg.AddExtension = true; dlg.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*" ; if (dlg.ShowDialog() == DialogResult.OK) { XmlTextWriter xw = new XmlTextWriter(dlg.FileName, System.Text.Encoding.UTF8); this.gridGroupingControl1.WriteXmlSchema(xw); xw.Close(); }
The code to load the schema is performed using a combination of XmlReader and CreateFromXml or ApplyXmlSchema.
FileDialog dlg = new OpenFileDialog(); dlg.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*" ; if (dlg.ShowDialog() == DialogResult.OK) { XmlReader xr = new XmlTextReader(dlg.FileName); GridEngine engine = GridEngine.CreateFromXml(xr); if (engine != null) this.gridGroupingControl1.Engine.InitializeFrom(engine); xr.Close(); }