Home   Free Applications   Code Snippets   Fun Stuff 
 
 You are here: Home > Free Applications > ComSerialization > Documentation
Register   Login  

 
Site Navigation


Print Print this page
Email E-mail this page
Bookmark Add to Favorites

 

Introduction

The ComSerialization component can be used to serializes and deserializes COM objects into and from XML documents. Serialization is the process of converting an object's public properties and fields to a serial format (in this case, XML) for storage or transport. Deserialization restores the object to its original state from the XML output. You can think of serialization as a way of saving the state of an object into a buffer.

XmlSerializer Object

Public Methods

  • Deserialize: Deserializes an XML document to the object reference
  • Serialize: Serializes an object into an XML document

    Public Properties

  • CollectionAddMethod: The name of the collection method that will return a reference to a collection item
  • IgnoreList: Semicolon delimited list of properties to ignore when serializing
  • LastError: The description of the last error that occurred

    Serialize Method

    Description

    Serializes an object into an XML document

    Syntax

    Public Function Serialize( _
        ByVal SourceObject As Object _
    ) As String

    Parameters

    SourceObject
        A reference to an object to be serialized

    Return Type

    Returns an XML string representing the serialization of the object

    Remarks

    The serialize method will serialize any readable property that does not have any parameters. If the property returns an object, it will be recursively serialized. Collections that support NewEnum will also be serialized.

    Use the IgnoreList to exclude spesific properties from serialization.

    Warning: Be sure to ignore properties that could cause an infinite loop, like parent.

    Serialization Limitations

    Arrays and User Defined types not supported.

    Example

        Dim oXmlSerializer As ComSerialization.XmlSerializer
        Dim oProject As Project
        Dim oTask As Task
        Dim oUser As User
        Dim sXML As String
    
        'create object
        Set oProject = New Project
    
        'add some test data
        With oProject
            .ProjectName = "Test"
            .ProjectID = 1
            .ProjectDescription = "This is a test"
            .TestDate = Now
    
            'example collection
            Set oUser = .Users.Add
            oUser.FirstName = "Me"
            oUser.LastName = "Moe"
            oUser.Email = "me@moe.com"
            oUser.Phone = "555-1212"
            Set oUser = Nothing
    
            'example collection
            Set oTask = .Tasks.Add
            oTask.TaskID = "123"
            oTask.TaskName = "test task"
            'example child object
            oTask.User.FirstName = "Test"
            oTask.User.LastName = "Person"
            Set oTask = Nothing
    
            'example collection
            Set oTask = .Tasks.Add
            oTask.TaskID = "222"
            oTask.TaskName = "second test task"
            'example child object
            oTask.User.FirstName = "Second"
            oTask.User.LastName = "Person"
            Set oTask = Nothing
    
        End With
    
        'create serialization object
        Set oXmlSerializer = New ComSerialization.XmlSerializer
    
        'return xml
        sXML = oXmlSerializer.Serialize(oProject)
    
        Debug.Print sXML	
    	

    Deserialize Method

    Description

    Deserializes an XML document to the object reference

    Syntax

    Public Function Deserialize( _
        ByVal TargetObject  As Object _
        ByVal sXML As Object _
    ) As Boolean

    Parameters

    TargetObject
        A reference to an object to be deserialized

    sXML
        XML string to deserialize to the object

    Remarks

    Deserialization Limitations

    1. Arrays and User Defined Types not supported
    2. Child objects will deserialize only if the property returns a valid reference to the object
    3. To deserialize a collection, the add method of the collection must return a valid reference to an object that has been added to the collection. The add method must not have any required parameters.  Note that collection keys will be lost on deserialization.  You may specify an alternate to the add method by setting CollectionAddMethod property

    Example

        Dim oXmlSerializer As ComSerialization.XmlSerializer
        Dim oProject As Project
    
        Set oXmlSerializer = New ComSerialization.XmlSerializer 'create the XmlSerializer
        Set oProject = New Project 'create a new object reference
    
        'call deserialize passing in object reference and xml
        'sXML is the xml string that was return from Serialize
        oXmlSerializer.Deserialize oProject, sXML
    
        'oProject's state should now be the same as it was when we serialized it
    	

    Conclusion

    Hope you find this component usefull.

    Paul Welter
    http://www.loresoft.com



  • Top

     
    SourceForge.net: Project Summary: LoreSoft.com Libraries (loresoft project)


    A summary of key project details for the loresoft project on SourceForge.net.

  • Project name: LoreSoft.com Libraries
    Project description: The LoreSoft.com libraries are a suit of VB Com object. Parcial list of objects include, ComSerialization, FileSearch, and GenLib.

  • Developers on project: 1
    Project administrators: pwelter34

  • Activity percentile (last week): 76.47%
    Most recent daily statistics (21 Jun 2008): Ranking: 52005, Activity percentile: 76.47%,

  • Downloadable files: 8719 total downloads to date
    Most recent daily statistics (21 Jun 2008): Download count:

  • Mailing lists (public): 1
    Public mailing lists: loresoft-commits

  • Tracker: Bugs (1 open/1 total)
    Tracker description: Bug Tracking System

  • Tracker: Support Requests (0 open/0 total)
    Tracker description: Tech Support Tracking System

  • Tracker: Patches (1 open/1 total)
    Tracker description: Patch Tracking System

  • Tracker: Feature Requests (0 open/0 total)
    Tracker description: Feature Request Tracking System


    Copyright and acceptable usage information for this RSS feed may be found at: http://sourceforge.net/docman/display_doc.php?docid=6048&group_id=1#licensing_and_other_terms Last Refreshed 7/23/2008 3:19:05 PM
  •