Smart Shapes Serialization
In This Topic
Smart Shapes can be serialized in Binary, SOAP, XML, Custom Binary and Custom XML format. There are two classes, which facilitate the persistency of smart shapes - NSmartShapeDocument and NSmartShapeDocumentSerializer.
The NSmartShapeDocument class is used as a container for a single smart shape. The smart shape, which is serialized with the document is specified by its Shape property. The document, together with the shape are serialized by an instance of the NSmartShapeDocumentSerializer class. For example:
C# |
Copy Code
|
// create a document, which will serialize the specified shape
NSmartShapeDocument document = new NSmartShapeDocument(smartShape);
// create a document serializer
NSmartShapeDocumentSerializer serializer = new NSmartShapeDocumentSerializer();
// save the document as an XML file
serializer.SaveToFile(document, "C:\\Temp\\MyFirstShapeDocument.nssx", PersistencyFormat.XML, null);
// load the document from the XML file
document = serializer.LoadFromFile("C:\\Temp\\MyFirstShapeDocument.nssx", PersistencyFormat.XML, null);
// get the loaded shape
NSmartShape shape = document.Shape;
|
Visual Basic |
Copy Code
|
' create a document, which will serialize the specified shape
Dim document As New NSmartShapeDocument(smartShape)
' create a document serializer
Dim serializer As New NSmartShapeDocumentSerializer()
' save the document as an XML file
serializer.SaveToFile(document, "C:\\Temp\\MyFirstShapeDocument.nssx", PersistencyFormat.XML, null)
' load the document from the XML file
document = serializer.LoadFromFile("C:\\Temp\\MyFirstShapeDocument.nssx", PersistencyFormat.XML, null)
' get the loaded shape
Dim shape As NSmartShape = document.Shape;
|
Persistency Formats and File Extensions
There are overloads of the SaveToFile and LoadFromFile methods in which the persistency format is not a required argument. These methods determine the persistency format based on the file extension. The following table summarizes the currently recognized file extensions:
Persistency Format |
Extension |
Binary |
.nssb (stands for Nevron Smart Shape Binary) |
XML |
.nssx (stands for Nevron Smart Shape XML) |
SOAP |
.nsss (stands for Nevron Smart Shape SOAP) |
Custom Binary |
.cnssb (stands for Custom Nevron Smart Shape Binary) |
Custom XML |
.cnssx (stands for Custom Nevron Smart Shape XML) |
Saving Smart Shape Documents
The serializer provides several methods, which facilitate the saving of smart shape documents to files or streams. Use the SaveToFile method to save the document to a file (has three overloads). Use the SaveToStream method to save the document to a stream.
Loading Smart Shape Documents
Analogously the serializer provides several methods, which facilitate the loading of smart shape documents from files or streams. Use the LoadFromFile method to load the document from a file (has three overloads). Use the LoadFromStream method to load the document from a stream.
See Also